-- ============================================================
-- BETKOOS - SEEDS PADRÃO
-- Dados iniciais para uma instalação nova
-- ============================================================

-- ------------------------------------------------------------
-- ADMIN PADRÃO (senha: admin123 - ALTERE APÓS LOGIN!)
-- ------------------------------------------------------------
INSERT INTO `users` (`phone`, `password_hash`, `currency`, `role`, `kyc_status`, `created_at`) VALUES
('840000000', '$2y$12$LQ5v3aZ7.KQxWv8E9N2mYO5qZqZqZqZqZqZqZqZqZqZqZqZqZqZqZ', 'MZN', 'admin', 'approved', NOW());

-- ------------------------------------------------------------
-- CONFIGURAÇÕES DO SISTEMA
-- ------------------------------------------------------------
INSERT INTO `system_settings` (`setting_key`, `setting_value`, `setting_type`, `setting_group`, `setting_label`, `setting_description`, `is_public`) VALUES
-- Depósitos
('deposit_min_mzn', '50', 'number', 'deposits', 'Depósito Mínimo (MZN)', 'Valor mínimo para depósito em Meticais', 1),
('deposit_max_mzn', '500000', 'number', 'deposits', 'Depósito Máximo (MZN)', 'Valor máximo para depósito em Meticais', 1),
('deposit_min_aoa', '500', 'number', 'deposits', 'Depósito Mínimo (AOA)', 'Valor mínimo para depósito em Kwanzas', 1),
('deposit_max_aoa', '5000000', 'number', 'deposits', 'Depósito Máximo (AOA)', 'Valor máximo para depósito em Kwanzas', 1),
('deposit_min_usd', '1', 'number', 'deposits', 'Depósito Mínimo (USD)', 'Valor mínimo para depósito em Dólares', 1),
('deposit_max_usd', '10000', 'number', 'deposits', 'Depósito Máximo (USD)', 'Valor máximo para depósito em Dólares', 1),

-- Saques
('withdraw_min_mzn', '100', 'number', 'withdrawals', 'Saque Mínimo (MZN)', 'Valor mínimo para saque em Meticais', 1),
('withdraw_max_mzn', '1000000', 'number', 'withdrawals', 'Saque Máximo (MZN)', 'Valor máximo para saque em Meticais', 1),
('withdraw_min_aoa', '1000', 'number', 'withdrawals', 'Saque Mínimo (AOA)', 'Valor mínimo para saque em Kwanzas', 1),
('withdraw_max_aoa', '10000000', 'number', 'withdrawals', 'Saque Máximo (AOA)', 'Valor máximo para saque em Kwanzas', 1),
('withdraw_min_usd', '2', 'number', 'withdrawals', 'Saque Mínimo (USD)', 'Valor mínimo para saque em Dólares', 1),
('withdraw_max_usd', '20000', 'number', 'withdrawals', 'Saque Máximo (USD)', 'Valor máximo para saque em Dólares', 1),
('withdraw_fee_percent', '6', 'number', 'withdrawals', 'Taxa de Saque (%)', 'Percentual de taxa para saques', 0),
('withdraw_auto_approve_max', '5000', 'number', 'withdrawals', 'Aprovação Automática Até', 'Saques até este valor são aprovados automaticamente', 0),

-- Apostas
('bet_min_mzn', '5', 'number', 'bets', 'Aposta Mínima (MZN)', 'Valor mínimo para aposta em Meticais', 1),
('bet_max_mzn', '50000', 'number', 'bets', 'Aposta Máxima (MZN)', 'Valor máximo para aposta em Meticais', 1),
('bet_min_aoa', '50', 'number', 'bets', 'Aposta Mínima (AOA)', 'Valor mínimo para aposta em Kwanzas', 1),
('bet_max_aoa', '500000', 'number', 'bets', 'Aposta Máxima (AOA)', 'Valor máximo para aposta em Kwanzas', 1),
('bet_min_usd', '0.10', 'number', 'bets', 'Aposta Mínima (USD)', 'Valor mínimo para aposta em Dólares', 1),
('bet_max_usd', '1000', 'number', 'bets', 'Aposta Máxima (USD)', 'Valor máximo para aposta em Dólares', 1),
('max_win_multiplier', '100', 'number', 'bets', 'Ganho Máximo (multiplicador)', 'Multiplicador máximo de ganho por aposta', 0),

-- Bónus
('welcome_bonus_percent', '100', 'number', 'bonuses', 'Bónus Boas-Vindas (%)', 'Percentagem do bónus no primeiro depósito', 1),
('welcome_bonus_max_mzn', '5000', 'number', 'bonuses', 'Bónus Máximo (MZN)', 'Valor máximo do bónus de boas-vindas', 1),
('welcome_wagering', '30', 'number', 'bonuses', 'Rollover do Bónus', 'Quantas vezes o bónus deve ser apostado', 0),
('welcome_bonus_validity_days', '7', 'number', 'bonuses', 'Validade do Bónus (dias)', 'Dias para usar o bónus antes de expirar', 0),

-- Afiliados
('affiliate_commission_percent', '25', 'number', 'affiliates', 'Comissão de Afiliado (%)', 'Percentagem fixa de RevShare vitalício', 0),
('affiliate_min_withdraw_mzn', '500', 'number', 'affiliates', 'Saque Mínimo Afiliado (MZN)', 'Valor mínimo para afiliado sacar comissão', 0),

-- Geral
('site_name', 'BetKoos', 'string', 'general', 'Nome do Site', 'Nome exibido no site', 1),
('site_currency_default', 'MZN', 'string', 'general', 'Moeda Padrão', 'Moeda padrão para novos registos', 1),
('maintenance_mode', '0', 'boolean', 'general', 'Modo Manutenção', 'Ativar/desativar modo manutenção', 0),
('min_age', '18', 'number', 'general', 'Idade Mínima', 'Idade mínima para jogar', 1),
('kyc_required_above', '10000', 'number', 'general', 'KYC Obrigatório Acima de', 'Valor de saque que exige KYC', 0),

-- Segurança
('max_login_attempts', '5', 'number', 'security', 'Máximo de Tentativas Login', 'Bloqueia após X tentativas falhas', 0),
('login_lockout_minutes', '15', 'number', 'security', 'Tempo de Bloqueio (min)', 'Minutos de bloqueio após falhas', 0),
('session_timeout_minutes', '60', 'number', 'security', 'Timeout da Sessão (min)', 'Minutos até sessão expirar', 0);

-- ------------------------------------------------------------
-- JOGOS PADRÃO
-- ------------------------------------------------------------
INSERT INTO `game_settings` (`game_key`, `game_name`, `house_edge_percent`, `prob_easy`, `prob_medium`, `prob_hard`, `min_bet`, `max_bet`, `max_win`) VALUES
('aviator', 'Aviator', 4.00, 50.00, 40.00, 10.00, 5.00, 50000.00, 500000.00),
('tower', 'Tower', 3.00, 60.00, 30.00, 10.00, 5.00, 50000.00, 500000.00),
('twinspin', 'Twin Spin', 5.00, 70.00, 25.00, 5.00, 25.00, 100000.00, 1000000.00),
('trader', 'Trader', 2.50, 55.00, 35.00, 10.00, 20.00, 50000.00, 500000.00),
('mines', 'Mines', 3.50, 60.00, 30.00, 10.00, 5.00, 50000.00, 500000.00),
('plinko', 'Plinko', 4.00, 50.00, 40.00, 10.00, 5.00, 50000.00, 500000.00);

-- ------------------------------------------------------------
-- GATEWAYS DE PAGAMENTO (vazios - admin preenche)
-- ------------------------------------------------------------
INSERT INTO `payment_gateways` (`gateway_key`, `gateway_name`, `environment`, `base_url`) VALUES
('zumopay', 'Zumbo Pay', 'test', 'https://zumbopay.com/api/public/v1'),
('paypal', 'PayPal', 'sandbox', 'https://api-m.sandbox.paypal.com');

-- ------------------------------------------------------------
-- TABELA gameOver (compatibilidade com jogos originais)
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `gameOver` (
    `id` INT PRIMARY KEY,
    `easy` DECIMAL(5,2) DEFAULT 50.00,
    `medium` DECIMAL(5,2) DEFAULT 40.00,
    `hard` DECIMAL(5,2) DEFAULT 10.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `gameOver` (`id`, `easy`, `medium`, `hard`) VALUES
(1, 50.00, 40.00, 10.00),  -- Geral
(2, 50.00, 40.00, 10.00),  -- Aviator
(3, 70.00, 25.00, 5.00),   -- Twin Spin / Tower
(4, 55.00, 35.00, 10.00),  -- Trader
(5, 60.00, 30.00, 10.00),  -- Mines
(6, 50.00, 40.00, 10.00);  -- Plinko

-- ------------------------------------------------------------
-- TABELA de Previsões (compatibilidade com index.php original)
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tbl_predictions` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `league` VARCHAR(100) NOT NULL,
    `team_home` VARCHAR(100) NOT NULL,
    `team_away` VARCHAR(100) NOT NULL,
    `question` VARCHAR(255) NOT NULL,
    `option_yes_odd` DECIMAL(6,2) NOT NULL,
    `option_no_odd` DECIMAL(6,2) NOT NULL,
    `event_date` DATETIME NOT NULL,
    `result` ENUM('pending','yes','no','cancelled') DEFAULT 'pending',
    `status` TINYINT(1) DEFAULT 1,
    `resolved_at` DATETIME NULL,
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Previsões de exemplo
INSERT INTO `tbl_predictions` (`league`, `team_home`, `team_away`, `question`, `option_yes_odd`, `option_no_odd`, `event_date`) VALUES
('Liga Moçambicana', 'Costa do Sol', 'Black Bulls', 'Haverá mais de 2.5 gols?', 1.85, 1.95, DATE_ADD(NOW(), INTERVAL 2 DAY)),
('Premier League', 'Manchester United', 'Liverpool', 'Liverpool marcará primeiro?', 2.10, 1.70, DATE_ADD(NOW(), INTERVAL 3 DAY)),
('La Liga', 'Real Madrid', 'Barcelona', 'Haverá cartões vermelhos?', 2.50, 1.50, DATE_ADD(NOW(), INTERVAL 5 DAY));

-- ------------------------------------------------------------
-- TABELAS de Boletim de Apostas (compatibilidade)
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tbl_prediction_bet_slip` (
    `id` BIGINT AUTO_INCREMENT PRIMARY KEY,
    `userid` INT NOT NULL,
    `stake` DECIMAL(18,2) NOT NULL,
    `total_odd` DECIMAL(10,2) NOT NULL,
    `potential_win` DECIMAL(18,2) NOT NULL,
    `status` ENUM('pending','won','lost','cancelled') DEFAULT 'pending',
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    INDEX `idx_user` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `tbl_prediction_bet_items` (
    `id` BIGINT AUTO_INCREMENT PRIMARY KEY,
    `slip_id` BIGINT NOT NULL,
    `prediction_id` INT NOT NULL,
    `choice` ENUM('yes','no') NOT NULL,
    `odd` DECIMAL(6,2) NOT NULL,
    `status` ENUM('pending','won','lost') DEFAULT 'pending',
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    INDEX `idx_slip` (`slip_id`),
    INDEX `idx_prediction` (`prediction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;