CREATE TABLE IF NOT EXISTS admins (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL,
    nama_lengkap VARCHAR(100),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS pesanan (
    id INT AUTO_INCREMENT PRIMARY KEY,
    nama_pelanggan VARCHAR(100) NOT NULL,
    whatsapp VARCHAR(20) NOT NULL,
    alamat_pengiriman TEXT,
    tanggal_kirim DATE,
    total_harga DECIMAL(10, 2),
    status ENUM('Baru', 'Proses', 'Selesai', 'Batal') DEFAULT 'Baru',
    catatan TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS pesanan_item (
    id INT AUTO_INCREMENT PRIMARY KEY,
    pesanan_id INT,
    menu_id INT,
    qty INT NOT NULL,
    harga_saat_pesan DECIMAL(10, 2) NOT NULL,
    FOREIGN KEY (pesanan_id) REFERENCES pesanan(id) ON DELETE CASCADE,
    FOREIGN KEY (menu_id) REFERENCES menu(id)
);

-- Default Admin: admin / admin123
INSERT INTO admins (username, password, nama_lengkap) 
VALUES ('admin', '$2y$10$2WEIuzHnD1ZJYg4WzJ9Wt.kfha4lyP3APX/LRki9OhnYf1T5yixjq', 'Administrator Ibu Tini');
