-- Run once to add new tables for progress tracking, workout plans, and reminder logging.
-- Also adds created_at to users if it doesn't already exist.

ALTER TABLE users ADD COLUMN IF NOT EXISTS created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;


CREATE TABLE IF NOT EXISTS progress (
    id         INT AUTO_INCREMENT PRIMARY KEY,
    chat_id    BIGINT        NOT NULL,
    weight     DECIMAL(5,2)  NOT NULL,
    note       VARCHAR(255)  DEFAULT NULL,
    logged_at  TIMESTAMP     DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_progress_chat (chat_id)
);

CREATE TABLE IF NOT EXISTS workout_plans (
    id         INT AUTO_INCREMENT PRIMARY KEY,
    chat_id    BIGINT        NOT NULL,
    plan       LONGTEXT      NOT NULL,
    created_at TIMESTAMP     DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_workout_chat (chat_id)
);

CREATE TABLE IF NOT EXISTS reminder_log (
    id           INT AUTO_INCREMENT PRIMARY KEY,
    chat_id      BIGINT       NOT NULL,
    reminder_key VARCHAR(100) NOT NULL,
    sent_at      TIMESTAMP    DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_reminder_chat_sent (chat_id, sent_at)
);
