CREATE TABLE admins (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(120) NOT NULL,
  email VARCHAR(190) NOT NULL UNIQUE,
  password_hash VARCHAR(255) NOT NULL,
  role ENUM('super_admin','editor','form_manager') DEFAULT 'editor',
  status TINYINT(1) DEFAULT 1,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE campaigns (
  id INT AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(255) NOT NULL,
  mobile_title VARCHAR(180) DEFAULT NULL,
  button_text VARCHAR(80) DEFAULT 'Teklif Al',
  button_url VARCHAR(255) DEFAULT 'teklif-al.php',
  gradient_start VARCHAR(20) DEFAULT '#dc2626',
  gradient_end VARCHAR(20) DEFAULT '#f97316',
  target_page VARCHAR(120) DEFAULT 'all',
  is_sticky TINYINT(1) DEFAULT 0,
  is_closable TINYINT(1) DEFAULT 0,
  status TINYINT(1) DEFAULT 1,
  start_at DATETIME DEFAULT NULL,
  end_at DATETIME DEFAULT NULL,
  clicks INT DEFAULT 0,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE blog_categories (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(120) NOT NULL,
  slug VARCHAR(160) NOT NULL UNIQUE,
  status TINYINT(1) DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE blogs (
  id INT AUTO_INCREMENT PRIMARY KEY,
  category_id INT DEFAULT NULL,
  title VARCHAR(255) NOT NULL,
  slug VARCHAR(255) NOT NULL UNIQUE,
  excerpt TEXT DEFAULT NULL,
  content LONGTEXT NOT NULL,
  cover_image VARCHAR(255) DEFAULT NULL,
  cover_alt VARCHAR(255) DEFAULT NULL,
  seo_title VARCHAR(255) DEFAULT NULL,
  seo_description VARCHAR(320) DEFAULT NULL,
  canonical_url VARCHAR(255) DEFAULT NULL,
  ai_summary TEXT DEFAULT NULL,
  focus_keyword VARCHAR(160) DEFAULT NULL,
  geo_location VARCHAR(160) DEFAULT NULL,
  faq_json LONGTEXT DEFAULT NULL,
  status ENUM('draft','published') DEFAULT 'draft',
  published_at DATETIME DEFAULT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  FOREIGN KEY (category_id) REFERENCES blog_categories(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE form_leads (
  id INT AUTO_INCREMENT PRIMARY KEY,
  form_type ENUM('contact','offer') NOT NULL,
  name VARCHAR(160) DEFAULT NULL,
  phone VARCHAR(80) DEFAULT NULL,
  email VARCHAR(190) DEFAULT NULL,
  company VARCHAR(190) DEFAULT NULL,
  subject VARCHAR(255) DEFAULT NULL,
  message TEXT DEFAULT NULL,
  raw_data LONGTEXT DEFAULT NULL,
  source_page VARCHAR(255) DEFAULT NULL,
  ip_address VARCHAR(80) DEFAULT NULL,
  status ENUM('new','called','offer_sent','waiting','closed','spam') DEFAULT 'new',
  admin_note TEXT DEFAULT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO blog_categories (name,slug) VALUES ('PVC Perde Rehberi','pvc-perde-rehberi');
INSERT INTO campaigns (title,mobile_title,button_text,button_url,status) VALUES ('Kış sezonuna özel PVC soğuk oda perdesi ve depo giriş perdelerinde hızlı teklif avantajı.','PVC perde hızlı teklif avantajı','Teklif Al','teklif-al.php',1);
