CREATE TABLE IF NOT EXISTS catalogue_gallery_imports (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  gallery_id INT UNSIGNED NOT NULL,
  title VARCHAR(500) NOT NULL DEFAULT '',
  batch_id VARCHAR(36) NOT NULL DEFAULT '',
  user_id INT UNSIGNED NULL DEFAULT NULL,
  status ENUM('pending','importing','completed','failed','skipped','cancelled') NOT NULL DEFAULT 'pending',
  album_id INT UNSIGNED NULL DEFAULT NULL,
  image_count INT UNSIGNED NOT NULL DEFAULT 0,
  attempt_count TINYINT UNSIGNED NOT NULL DEFAULT 0,
  max_attempts TINYINT UNSIGNED NOT NULL DEFAULT 3,
  error_message VARCHAR(1000) NULL DEFAULT NULL,
  video_type VARCHAR(20) NOT NULL DEFAULT 'hetero',
  import_settings TEXT NULL DEFAULT NULL,
  ai_settings LONGTEXT NULL DEFAULT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  started_at DATETIME NULL DEFAULT NULL,
  completed_at DATETIME NULL DEFAULT NULL,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  UNIQUE KEY uniq_gallery (gallery_id),
  KEY idx_status (status, id),
  KEY idx_batch (batch_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
