
-- USERS
CREATE TABLE IF NOT EXISTS `users` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `role` VARCHAR(20) NOT NULL,
  `name` VARCHAR(150) NOT NULL,
  `email` VARCHAR(150) NOT NULL UNIQUE,
  `password_hash` VARCHAR(255) NOT NULL,
  `status` VARCHAR(20) DEFAULT 'active',
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- SATIŞÇILAR
CREATE TABLE IF NOT EXISTS `satiscilar` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `user_id` INT NOT NULL,
  `ad_soyad` VARCHAR(150) NOT NULL,
  `phone` VARCHAR(50),
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- RESTORANLAR
CREATE TABLE IF NOT EXISTS `restoranlar` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `satisci_id` INT NOT NULL,
  `name` VARCHAR(200) NOT NULL,
  `contact_name` VARCHAR(150),
  `email` VARCHAR(150),
  `phone` VARCHAR(50),
  `address` TEXT,
  `trial_start` DATE,
  `trial_end` DATE,
  `paket` VARCHAR(20) DEFAULT 'trial',
  `fiyat` DECIMAL(10,2) DEFAULT 0,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- ÖDEMELER
CREATE TABLE IF NOT EXISTS `odemeler` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `restoran_id` INT NOT NULL,
  `tutar` DECIMAL(10,2) NOT NULL,
  `durum` VARCHAR(20) DEFAULT 'beklemede',
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- VARSAYILAN SÜPER ADMİN
INSERT INTO `users` (`role`, `name`, `email`, `password_hash`, `status`)
SELECT 'superadmin','Sistem Sahibi','admin@demo.com',
'$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
'active'
WHERE NOT EXISTS (SELECT 1 FROM users WHERE email='admin@demo.com');

