CREATE TABLE rooms (
    id      INTEGER PRIMARY KEY AUTOINCREMENT,
    number  TEXT NOT NULL UNIQUE,
    status  TEXT NOT NULL DEFAULT 'clean'
);

CREATE TABLE IF NOT EXISTS "conversation" (
    `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,
    `creator_id` INTEGER,
    `title` TEXT,
    `created_at` TEXT DEFAULT (CURRENT_TIMESTAMP)
);

CREATE TABLE IF NOT EXISTS "message" (
    `id` INTEGER PRIMARY KEY AUTOINCREMENT,
    `conversation_id` INTEGER REFERENCES `conversation`(`id`),
    `sender_id` INTEGER NOT NULL, `content` TEXT NOT NULL,
    `sent_at` TEXT DEFAULT (CURRENT_TIMESTAMP)
);

CREATE TABLE "conversation_participants" (
    `conversation_id` INTEGER NOT NULL REFERENCES `conversation`(`id`),
    `user_id` INTEGER NOT NULL,
    `joined_at` TEXT DEFAULT (CURRENT_TIMESTAMP)
    PRIMARY KEY (conversation_id, user_id)
);

CREATE TABLE IF NOT EXISTS "inventory" (
    `id` INTEGER PRIMARY KEY AUTOINCREMENT,
    `amount` INTEGER,
    `item_name` TEXT,
    `user_id` INT,
    `updated_at` TEXT DEFAULT (CURRENT_TIMESTAMP)
    );

CREATE TABLE IF NOT EXISTS "room_history" (
    `id` INTEGER PRIMARY KEY AUTOINCREMENT,
    `room_id` INTEGER NOT NULL REFERENCES `rooms`(`id`),
    `room_number` TEXT NOT NULL,
    `status` TEXT,
    `updated_at` TEXT DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS "inventory_history" (
    `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,
    `item_id` INTEGER NOT NULL REFERENCES `inventory`(`id`),
    `amount` INTEGER NOT NULL,
    `item_name` TEXT,
    `user_id` INT,
    `updated_at` TEXT DEFAULT (CURRENT_TIMESTAMP));

