-- ============================================================
-- Run this in phpMyAdmin or MySQL Workbench if game_settings
-- table does not exist and Games Manager page shows error.
-- ============================================================
USE mtplayyyy;

CREATE TABLE IF NOT EXISTS game_settings (
    id INT AUTO_INCREMENT PRIMARY KEY,
    game_key VARCHAR(60) NOT NULL UNIQUE,
    name VARCHAR(100) NOT NULL,
    category ENUM('lottery','popular','slots','casino','sports','rummy','fishing','original') NOT NULL DEFAULT 'popular',
    provider ENUM('internal','jili','jdb') NOT NULL DEFAULT 'internal',
    image_url VARCHAR(255) NOT NULL DEFAULT '',
    action_type ENUM('link','jili','jdb') NOT NULL DEFAULT 'link',
    action_value VARCHAR(255) NOT NULL DEFAULT '',
    action_extra VARCHAR(100) NOT NULL DEFAULT '',
    win_rate VARCHAR(10) NOT NULL DEFAULT '',
    sort_order INT NOT NULL DEFAULT 0,
    is_enabled TINYINT(1) NOT NULL DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Seed lottery games
INSERT IGNORE INTO game_settings (game_key, name, category, provider, image_url, action_type, action_value, sort_order) VALUES
('wingo',     'Win Go',     'lottery', 'internal', '/assets/png/wingo1-26adecc4.png',   'link', '/wingo?game_type=1',     1),
('k3',        'K3',         'lottery', 'internal', '/assets/png/k39-707408c6.png',       'link', '/k3?game_type=1',        2),
('5d',        '5D',         'lottery', 'internal', '/assets/png/bigMumbai-5c1b147a.png', 'link', '/5d?game_type=1',        3),
('trx_wingo', 'Trx Win Go', 'lottery', 'internal', '/assets/png/trxbg-38af3973.png',     'link', '/trx_wingo?game_type=1', 4);

-- Seed popular games
INSERT IGNORE INTO game_settings (game_key, name, category, provider, image_url, action_type, action_value, win_rate, sort_order) VALUES
('popular_jili_224',  'Rummy',        'popular', 'jili', '/jili_games/GAMEID_224.png', 'jili', '224',   '85.96%', 1),
('popular_jili_1',    'Golden Empire','popular', 'jili', '/jili_games/GAMEID_01.png',  'jili', '1',     '85.14%', 2),
('popular_jili_100',  'Crazy777',     'popular', 'jili', '/jili_games/GAMEID_100.png', 'jili', '100',   '84.9%',  3),
('popular_jili_119',  'Mega Ace',     'popular', 'jili', '/jili_games/GAMEID_119.png', 'jili', '119',   '91.42%', 4);

-- Seed original games (JDB)
INSERT IGNORE INTO game_settings (game_key, name, category, provider, image_url, action_type, action_value, action_extra, sort_order) VALUES
('orig_jdb_22001','Aviator','original','jdb','/jdb_images/22001_200x200_en.png','jdb','22001','22',1),
('orig_jdb_22002','Mines',  'original','jdb','/jdb_images/22002_200x200_en.png','jdb','22002','22',2),
('orig_jdb_22003','Plinko', 'original','jdb','/jdb_images/22003_200x200_en.png','jdb','22003','22',3),
('orig_jdb_22004','Hilo',   'original','jdb','/jdb_images/22004_200x200_en.png','jdb','22004','22',4),
('orig_jdb_22005','Dice',   'original','jdb','/jdb_images/22005_200x200_en.png','jdb','22005','22',5),
('orig_jdb_22008','Crash',  'original','jdb','/jdb_images/22008_200x200_en.png','jdb','22008','22',6);

SELECT CONCAT('game_settings has ', COUNT(*), ' games') AS result FROM game_settings;
