-- Script Database Lucky Spin Pro
-- Database: kamuxqoi_db_luckyspin

-- 1. Tabel untuk menyimpan daftar hadiah pada roda
CREATE TABLE IF NOT EXISTS `prizes` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `name` VARCHAR(100) NOT NULL,
    `chance` INT NOT NULL COMMENT 'Bobot probabilitas',
    `color` VARCHAR(20) NOT NULL COMMENT 'Kode warna HEX',
    `text_color` VARCHAR(20) DEFAULT '#ffffff'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 2. Tabel untuk menyimpan pengaturan UI website
CREATE TABLE IF NOT EXISTS `settings` (
    `setting_key` VARCHAR(50) PRIMARY KEY,
    `setting_value` TEXT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 3. Tabel untuk menyimpan kode voucher
CREATE TABLE IF NOT EXISTS `vouchers` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `code` VARCHAR(50) UNIQUE NOT NULL,
    `is_used` TINYINT(1) DEFAULT 0,
    `prize_id` INT NULL,
    `used_at` DATETIME NULL,
    CONSTRAINT `fk_prize` FOREIGN KEY (`prize_id`) REFERENCES `prizes`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 4. Inisialisasi Data Hadiah Default
INSERT INTO `prizes` (`name`, `chance`, `color`) VALUES 
('Zonk / Coba Lagi', 60, '#e74c3c'),
('Voucher 5K', 15, '#f1c40f'),
('Voucher 10K', 10, '#2ecc71'),
('Saldo 50K', 4, '#3498db'),
('Jackpot iPhone', 1, '#9b59b6');

-- 5. Inisialisasi Pengaturan Visual Website
INSERT INTO `settings` (`setting_key`, `setting_value`) VALUES 
('site_title', 'LUCKY SPIN PREMIUM'),
('primary_color', '#f1c40f'),
('bg_color', '#0f172a'),
('wheel_border', '#1e293b'),
('footer_text', 'Copyright © 2025 Lucky Spin System');