-- Game completion detection log table
CREATE TABLE IF NOT EXISTS game_completion_log (
  id BIGINT PRIMARY KEY AUTO_INCREMENT,
  link_task_id BIGINT,
  machine_id VARCHAR(64),
  detection_source VARCHAR(32),
  device_status VARCHAR(64),
  points_detected INT NULL,
  completion_confidence VARCHAR(16),
  is_confirmed TINYINT(1) DEFAULT 0,
  confirmation_time DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_gcl_task (link_task_id),
  INDEX idx_gcl_machine (machine_id),
  INDEX idx_gcl_created (created_at)
);

-- Link task status transition history
CREATE TABLE IF NOT EXISTS link_task_status_history (
  id BIGINT PRIMARY KEY AUTO_INCREMENT,
  link_task_id BIGINT,
  code_no VARCHAR(64),
  machine_id VARCHAR(64),
  prev_status VARCHAR(32),
  new_status VARCHAR(32),
  source VARCHAR(32),
  reason VARCHAR(128),
  since_login_seconds INT NULL,
  extra_json TEXT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_ltsh_task (link_task_id),
  INDEX idx_ltsh_code (code_no),
  INDEX idx_ltsh_machine (machine_id),
  INDEX idx_ltsh_created (created_at)
);

