-- Yasal sayfa avukat onayı alanları (site_pages). Eski veritabanları için; idempotent.
-- MySQL 8+ / MariaDB 10.3+

USE faunamix;

SET @has_confirmed := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'site_pages' AND COLUMN_NAME = 'legal_review_confirmed'
);
SET @sql_confirmed := IF(@has_confirmed = 0,
  'ALTER TABLE site_pages ADD COLUMN legal_review_confirmed TINYINT(1) NOT NULL DEFAULT 0 AFTER is_active',
  'SELECT 1');
PREPARE stmt FROM @sql_confirmed; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @has_note := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'site_pages' AND COLUMN_NAME = 'legal_review_note'
);
SET @sql_note := IF(@has_note = 0,
  'ALTER TABLE site_pages ADD COLUMN legal_review_note VARCHAR(1024) NOT NULL DEFAULT '''' AFTER legal_review_confirmed',
  'SELECT 1');
PREPARE stmt FROM @sql_note; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @has_at := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'site_pages' AND COLUMN_NAME = 'legal_review_confirmed_at'
);
SET @sql_at := IF(@has_at = 0,
  'ALTER TABLE site_pages ADD COLUMN legal_review_confirmed_at DATETIME NULL DEFAULT NULL AFTER legal_review_note',
  'SELECT 1');
PREPARE stmt FROM @sql_at; EXECUTE stmt; DEALLOCATE PREPARE stmt;
