<?php
declare(strict_types=1);
require __DIR__ . '/../../config/bootstrap.php';

use App\Core\Database;

$db = Database::getInstance();

$db->exec("
CREATE TABLE IF NOT EXISTS conference_committees (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  conference_id BIGINT UNSIGNED NOT NULL,
  committee_type VARCHAR(80) NOT NULL DEFAULT 'committee',
  title_en VARCHAR(255) DEFAULT NULL,
  title_ar VARCHAR(255) DEFAULT NULL,
  description_en TEXT DEFAULT NULL,
  description_ar TEXT DEFAULT NULL,
  sort_order INT NOT NULL DEFAULT 0,
  is_active TINYINT(1) NOT NULL DEFAULT 1,
  created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_conf (conference_id),
  KEY idx_type (committee_type),
  KEY idx_active (is_active),
  CONSTRAINT fk_cc_conf FOREIGN KEY (conference_id) REFERENCES conferences(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
");

$db->exec("
CREATE TABLE IF NOT EXISTS conference_committee_members (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  committee_id BIGINT UNSIGNED NOT NULL,
  full_name VARCHAR(255) NOT NULL,
  role_title VARCHAR(255) DEFAULT NULL,
  email VARCHAR(190) DEFAULT NULL,
  affiliation VARCHAR(255) DEFAULT NULL,
  photo_path VARCHAR(255) DEFAULT NULL,
  sort_order INT NOT NULL DEFAULT 0,
  is_active TINYINT(1) NOT NULL DEFAULT 1,
  created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_committee (committee_id),
  KEY idx_active (is_active),
  CONSTRAINT fk_ccm_committee FOREIGN KEY (committee_id) REFERENCES conference_committees(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
");

echo "OK: Committees tables ready\n";
