USE mtplayyyy;

-- minutes_1 (wingo bets table - main betting table)
CREATE TABLE IF NOT EXISTS minutes_1 (
    id int(11) NOT NULL AUTO_INCREMENT,
    id_product varchar(50) NOT NULL DEFAULT '0',
    phone varchar(20) NOT NULL DEFAULT '0',
    game varchar(20) NOT NULL DEFAULT '0',
    period varchar(30) NOT NULL DEFAULT '0',
    bet varchar(20) NOT NULL DEFAULT '0',
    money float NOT NULL DEFAULT 0,
    fee float NOT NULL DEFAULT 0,
    get float NOT NULL DEFAULT 0,
    status int(11) NOT NULL DEFAULT 0,
    today datetime NOT NULL DEFAULT current_timestamp(),
    time varchar(50) NOT NULL DEFAULT '0',
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- user_bank (user bank/USDT accounts)
CREATE TABLE IF NOT EXISTS user_bank (
    id int(11) NOT NULL AUTO_INCREMENT,
    phone varchar(20) NOT NULL DEFAULT '0',
    name_bank varchar(100) NOT NULL DEFAULT '0',
    name_user varchar(100) NOT NULL DEFAULT '0',
    stk varchar(100) NOT NULL DEFAULT '0',
    tinh varchar(50) NOT NULL DEFAULT '0',
    chi_nhanh varchar(100) NOT NULL DEFAULT '0',
    sdt varchar(50) NOT NULL DEFAULT '0',
    tp varchar(20) NOT NULL DEFAULT 'bank',
    time varchar(50) NOT NULL DEFAULT '0',
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- commissions
CREATE TABLE IF NOT EXISTS commissions (
    id int(11) NOT NULL AUTO_INCREMENT,
    commission_id varchar(50) NOT NULL DEFAULT '0',
    phone varchar(20) NOT NULL DEFAULT '0',
    from_user_phone varchar(20) NOT NULL DEFAULT '0',
    money float NOT NULL DEFAULT 0,
    level int(11) NOT NULL DEFAULT 0,
    time varchar(50) NOT NULL DEFAULT '0',
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- withdraw: add missing columns if not present
ALTER TABLE withdraw ADD COLUMN IF NOT EXISTS id_order varchar(100) NOT NULL DEFAULT '0';
ALTER TABLE withdraw ADD COLUMN IF NOT EXISTS name_bank varchar(100) NOT NULL DEFAULT '0';
ALTER TABLE withdraw ADD COLUMN IF NOT EXISTS name_user varchar(100) NOT NULL DEFAULT '0';
ALTER TABLE withdraw ADD COLUMN IF NOT EXISTS stk varchar(100) NOT NULL DEFAULT '0';
ALTER TABLE withdraw ADD COLUMN IF NOT EXISTS ifsc varchar(50) NOT NULL DEFAULT '0';
ALTER TABLE withdraw ADD COLUMN IF NOT EXISTS sdt varchar(50) NOT NULL DEFAULT '0';
ALTER TABLE withdraw ADD COLUMN IF NOT EXISTS tp varchar(20) NOT NULL DEFAULT 'bank';
ALTER TABLE withdraw ADD COLUMN IF NOT EXISTS remarks varchar(255) NOT NULL DEFAULT '';
ALTER TABLE withdraw ADD COLUMN IF NOT EXISTS order_id varchar(100) NOT NULL DEFAULT '';

-- recharge: add missing columns
ALTER TABLE recharge ADD COLUMN IF NOT EXISTS type varchar(20) NOT NULL DEFAULT '0';

-- trx_hash table
CREATE TABLE IF NOT EXISTS trx_hash (
    id int(11) NOT NULL AUTO_INCREMENT,
    hash varchar(100) NOT NULL DEFAULT '0',
    phone varchar(20) NOT NULL DEFAULT '0',
    money float NOT NULL DEFAULT 0,
    status int(11) NOT NULL DEFAULT 0,
    time varchar(50) NOT NULL DEFAULT '0',
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- gift_vouchers / redenvelopes
CREATE TABLE IF NOT EXISTS redenvelopes (
    id int(11) NOT NULL AUTO_INCREMENT,
    code varchar(50) NOT NULL DEFAULT '0',
    money float NOT NULL DEFAULT 0,
    status int(11) NOT NULL DEFAULT 0,
    time varchar(50) NOT NULL DEFAULT '0',
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

CREATE TABLE IF NOT EXISTS redenvelopes_used (
    id int(11) NOT NULL AUTO_INCREMENT,
    phone varchar(20) NOT NULL DEFAULT '0',
    code varchar(50) NOT NULL DEFAULT '0',
    money float NOT NULL DEFAULT 0,
    time varchar(50) NOT NULL DEFAULT '0',
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- vip_level table
CREATE TABLE IF NOT EXISTS vip_level (
    id int(11) NOT NULL AUTO_INCREMENT,
    level int(11) NOT NULL DEFAULT 0,
    min_bet float NOT NULL DEFAULT 0,
    max_bet float NOT NULL DEFAULT 0,
    bonus float NOT NULL DEFAULT 0,
    time varchar(50) NOT NULL DEFAULT '0',
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

SELECT 'All remaining tables created!' AS status;
