CREATE DATABASE IF NOT EXISTS idn_slot CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE idn_slot;

CREATE TABLE users (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    password_hash VARCHAR(255) NOT NULL,
    role ENUM('member','admin') NOT NULL DEFAULT 'member',
    credits DECIMAL(15,2) NOT NULL DEFAULT 10000.00,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE spins (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id INT UNSIGNED NOT NULL,
    bet DECIMAL(15,2) NOT NULL,
    win DECIMAL(15,2) NOT NULL,
    reels JSON NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX(user_id),
    CONSTRAINT fk_spins_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
);
