-- Athena Auth: enterprise email operations support (admin lifecycle + failure triage)

ALTER TABLE email_send_failures
    ADD COLUMN IF NOT EXISTS resolved BOOLEAN NOT NULL DEFAULT FALSE;

ALTER TABLE email_send_failures
    ADD COLUMN IF NOT EXISTS resolution_note TEXT;

ALTER TABLE email_send_failures
    ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW();

CREATE INDEX IF NOT EXISTS idx_email_send_failures_resolved
    ON email_send_failures (resolved);

CREATE INDEX IF NOT EXISTS idx_email_send_failures_flow
    ON email_send_failures (flow);

ALTER TABLE emails
    ADD COLUMN IF NOT EXISTS flow TEXT;

ALTER TABLE emails
    ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW();

CREATE INDEX IF NOT EXISTS idx_emails_provider ON emails (provider);

CREATE INDEX IF NOT EXISTS idx_emails_flow ON emails (flow);
