-- 009_id_upload.sql
-- One-time upload tokens for ID verification (Anytime Mailbox registration).
-- Supports both desktop file upload and mobile QR code → phone camera upload.

BEGIN;

CREATE TABLE IF NOT EXISTS id_upload_tokens (
    id              SERIAL PRIMARY KEY,
    token           TEXT UNIQUE NOT NULL,
    order_type      TEXT DEFAULT 'canada_crtc',
    order_reference TEXT,
    customer_email  TEXT NOT NULL,
    customer_name   TEXT,
    front_uploaded  BOOLEAN DEFAULT FALSE,
    back_uploaded   BOOLEAN DEFAULT FALSE,
    minio_paths     JSONB DEFAULT '{}',
    expires_at      TIMESTAMPTZ NOT NULL,
    used            BOOLEAN DEFAULT FALSE,
    created_at      TIMESTAMPTZ DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_id_tokens_token ON id_upload_tokens(token);
CREATE INDEX IF NOT EXISTS idx_id_tokens_expires ON id_upload_tokens(expires_at);

COMMIT;
