-- migrations/001_initial_schema.up.sql

CREATE TABLE rooms (
    id TEXT PRIMARY KEY,
    created_at TIMESTAMP NOT NULL,
    creator_name TEXT NOT NULL,
    team_turn TEXT,
    this_turn_limit INTEGER,
    opened_this_turn INTEGER,
    blue_counter INTEGER,
    red_counter INTEGER,
    red_turn BOOLEAN,
    mime_done BOOLEAN,
    is_public BOOLEAN,
    is_running BOOLEAN,
    language TEXT,
    round_time INTEGER,
    is_over BOOLEAN,
    team_won TEXT,
    room_pass TEXT
);

CREATE TABLE players (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    room_id TEXT NOT NULL,
    username TEXT NOT NULL,
    team TEXT, -- 'red' or 'blue'
    role TEXT, -- 'guesser' or 'mime'
    is_bot BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (room_id) REFERENCES rooms(id)
);

CREATE TABLE word_cards (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    room_id TEXT NOT NULL,
    word TEXT NOT NULL,
    color TEXT,
    revealed BOOLEAN DEFAULT FALSE,
    mime_view BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (room_id) REFERENCES rooms(id)
);

CREATE TABLE card_marks (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    card_id INTEGER NOT NULL,
    username TEXT NOT NULL,
    active BOOLEAN DEFAULT TRUE,
    FOREIGN KEY (card_id) REFERENCES word_cards(id)
);

CREATE TABLE actions (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    room_id TEXT NOT NULL,
    actor TEXT NOT NULL,
    actor_color TEXT,
    action_type TEXT NOT NULL,
    word TEXT,
    word_color TEXT,
    number_associated TEXT, -- for clues
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (room_id) REFERENCES rooms(id)
);
