CREATE TABLE users (
    id INT PRIMARY KEY AUTO_INCREMENT,
    user_id BIGINT UNIQUE NOT NULL,
    username VARCHAR(255),
    is_admin BOOLEAN DEFAULT false,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE submissions (
    id INT PRIMARY KEY AUTO_INCREMENT,
    user_id BIGINT NOT NULL,
    submission_date DATE NOT NULL,
    count INT DEFAULT 0,
    FOREIGN KEY (user_id) REFERENCES users(user_id)
);

CREATE TABLE stats (
    id INT PRIMARY KEY AUTO_INCREMENT,
    stat_type ENUM('user', 'request') NOT NULL,
    period_type ENUM('daily', 'weekly', 'monthly', 'total') NOT NULL,
    period_value VARCHAR(10) NOT NULL,
    value INT NOT NULL
);

CREATE TABLE popular_items (
    id INT PRIMARY KEY AUTO_INCREMENT,
    item_type ENUM('dining', 'meal') NOT NULL,
    item_name VARCHAR(255) NOT NULL,
    count INT DEFAULT 0,
    UNIQUE KEY (item_type, item_name)
);

CREATE TABLE user_states (
    user_id BIGINT PRIMARY KEY,
    state_data TEXT,
    last_message_id INT,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);