-- SSS (FAQ) tablosu: global, kategori bazlı, ürün bazlı, sayfa bazlı sorular. idempotent

CREATE TABLE IF NOT EXISTS faqs (
  id          INT UNSIGNED NOT NULL AUTO_INCREMENT,
  scope       ENUM('global','category','product','page') NOT NULL DEFAULT 'global',
  reference_id INT UNSIGNED NULL DEFAULT NULL,   -- category_id, product_id veya site_page id
  question    TEXT NOT NULL,
  answer      TEXT NOT NULL,
  sort_order  SMALLINT NOT NULL DEFAULT 0,
  is_active   TINYINT(1) NOT NULL DEFAULT 1,
  created_at  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_faqs_scope_ref_active (scope, reference_id, is_active, sort_order)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Mevcut kurulumlar için scope sütununu genişlet (idempotent — hata vermez)
ALTER TABLE faqs MODIFY COLUMN scope ENUM('global','category','product','page') NOT NULL DEFAULT 'global';
