-- EnglishSpeak Dialogue / Ask & Answer
CREATE TABLE IF NOT EXISTS dialogue_sets (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(255) NOT NULL,
  description TEXT NULL,
  status VARCHAR(20) NOT NULL DEFAULT 'active',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_dialogue_sets_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS dialogue_items (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  dialogue_set_id BIGINT UNSIGNED NOT NULL,
  sort_order INT NOT NULL DEFAULT 1,
  speaker_name VARCHAR(80) NOT NULL DEFAULT 'A',
  prompt_text TEXT NOT NULL,
  correct_response TEXT NOT NULL,
  distractor_1 TEXT NULL,
  distractor_2 TEXT NULL,
  distractor_3 TEXT NULL,
  prompt_audio VARCHAR(500) NULL,
  response_audio VARCHAR(500) NULL,
  image_path VARCHAR(500) NULL,
  status VARCHAR(20) NOT NULL DEFAULT 'active',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY idx_dialogue_items_set (dialogue_set_id, sort_order),
  CONSTRAINT fk_dialogue_items_set FOREIGN KEY (dialogue_set_id)
    REFERENCES dialogue_sets(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
