CREATE EXTENSION IF NOT EXISTS "pgcrypto";

CREATE TABLE session_audit_log (
    id                  UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    session_id          UUID NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
    actor_telegram_id   BIGINT NOT NULL,
    actor_name          VARCHAR(255) NOT NULL,
    change_type         VARCHAR(50) NOT NULL
                        CHECK (change_type IN ('Title','Time','Link','MaxPlayers','Status','WaitlistPromote','PlayerRemoved','BatchRescheduled','Cancelled')),
    old_value           TEXT,
    new_value           TEXT,
    changed_at          TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX ix_session_audit_log_session_id ON session_audit_log(session_id);
CREATE INDEX ix_session_audit_log_changed_at ON session_audit_log(changed_at);
