USE mtplayyyy;

-- point_list table (used by dailyController, adminController, userController)
CREATE TABLE IF NOT EXISTS point_list (
    id int(11) NOT NULL AUTO_INCREMENT,
    phone varchar(20) NOT NULL DEFAULT '0',
    level int(11) NOT NULL DEFAULT 0,
    money float NOT NULL DEFAULT 0,
    money_us float NOT NULL DEFAULT 0,
    total1 float NOT NULL DEFAULT 0,
    total2 float NOT NULL DEFAULT 0,
    total3 float NOT NULL DEFAULT 0,
    total4 float NOT NULL DEFAULT 0,
    total5 float NOT NULL DEFAULT 0,
    total6 float NOT NULL DEFAULT 0,
    total7 float NOT NULL DEFAULT 0,
    telegram varchar(100) NOT NULL DEFAULT '0',
    time varchar(50) NOT NULL DEFAULT '0',
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- financial_details table (used by dailyController)
CREATE TABLE IF NOT EXISTS financial_details (
    id int(11) NOT NULL AUTO_INCREMENT,
    phone varchar(20) NOT NULL DEFAULT '0',
    money float NOT NULL DEFAULT 0,
    type varchar(50) 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;

-- Ensure every existing user has a point_list row
INSERT IGNORE INTO point_list (phone, level, money, money_us, time)
SELECT phone, level, 0, 0, time FROM users WHERE phone NOT IN (SELECT phone FROM point_list);

SELECT 'point_list and financial_details tables created!' AS status;
