-- Create database
CREATE DATABASE IF NOT EXISTS kiosk_system;
USE kiosk_system;

-- Payments table
CREATE TABLE IF NOT EXISTS payments (
    id INT AUTO_INCREMENT PRIMARY KEY,
    billcode VARCHAR(100) UNIQUE NOT NULL,
    external_ref VARCHAR(100),
    amount DECIMAL(10,2) NOT NULL,
    status ENUM('pending', 'paid', 'failed') DEFAULT 'pending',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_billcode (billcode),
    INDEX idx_status (status),
    INDEX idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Settings table
CREATE TABLE IF NOT EXISTS settings (
    id INT AUTO_INCREMENT PRIMARY KEY,
    setting_key VARCHAR(100) UNIQUE NOT NULL,
    setting_value TEXT,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Insert default settings
INSERT INTO settings (setting_key, setting_value) VALUES
('api_key', 'your-toyyibpay-api-key'),
('category_code', 'your-category-code'),
('org_name', 'KIOSK PAYMENT SYSTEM'),
('org_email', 'admin@kiosk.com'),
('org_phone', '+60123456789'),
('reset_timer_success', '8'),
('reset_timer_failed', '10'),
('reset_timer_idle', '45'),
('sound_enabled', '1'),
('currency', 'RM'),
('receipt_footer', 'Thank You For Your Payment');
-- Default password hash for 'admin123' - CHANGE THIS AFTER FIRST LOGIN!