USE mtplayyyy;

-- 1. Add missing columns to wingo table
ALTER TABLE wingo ADD COLUMN IF NOT EXISTS release_status int(11) NOT NULL DEFAULT 0;
ALTER TABLE wingo ADD COLUMN IF NOT EXISTS result varchar(10) NOT NULL DEFAULT '0';

-- 2. Add missing columns to trx_wingo_bets table
ALTER TABLE trx_wingo_bets ADD COLUMN IF NOT EXISTS result varchar(10) NOT NULL DEFAULT '0';

-- 3. Create admin_ac table (used by home, wingo, k3, k5d controllers)
CREATE TABLE IF NOT EXISTS admin_ac (
    id int(11) NOT NULL AUTO_INCREMENT,
    wingo1 text NOT NULL,
    wingo3 text NOT NULL,
    wingo5 text NOT NULL,
    wingo10 text NOT NULL,
    k5d text NOT NULL,
    k5d3 text NOT NULL,
    k5d5 text,
    k5d10 text NOT NULL,
    win_rate int(11) NOT NULL DEFAULT 80,
    telegram varchar(100) NOT NULL DEFAULT 'https://t.me/Olivia_XDR',
    cskh varchar(100) NOT NULL DEFAULT 'https://t.me/Olivia_XDR',
    app varchar(100) NOT NULL DEFAULT '#',
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- Insert default admin_ac row
INSERT IGNORE INTO admin_ac (id, wingo1, wingo3, wingo5, wingo10, k5d, k5d3, k5d5, k5d10, win_rate, telegram, cskh, app)
VALUES (1, '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', 80, 'https://t.me/Olivia_XDR', 'https://t.me/Olivia_XDR', '#');

-- 4. Create result tables used by k3 and 5d controllers
CREATE TABLE IF NOT EXISTS result_5d (
    id int(11) NOT NULL AUTO_INCREMENT,
    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,
    price float NOT NULL DEFAULT 0,
    amount float NOT NULL DEFAULT 0,
    status int(11) NOT NULL DEFAULT 0,
    level 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;

CREATE TABLE IF NOT EXISTS result_k3 (
    id int(11) NOT NULL AUTO_INCREMENT,
    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,
    price float NOT NULL DEFAULT 0,
    typeGame varchar(20) NOT NULL DEFAULT '0',
    amount float NOT NULL DEFAULT 0,
    status int(11) NOT NULL DEFAULT 0,
    level 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;

CREATE TABLE IF NOT EXISTS result_wingo (
    id int(11) NOT NULL AUTO_INCREMENT,
    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,
    price float NOT NULL DEFAULT 0,
    amount float NOT NULL DEFAULT 0,
    status int(11) NOT NULL DEFAULT 0,
    level 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;

SELECT 'All fixes applied!' AS status;
