-- Athena Auth: audit log of successfully sent emails

CREATE TABLE IF NOT EXISTS emails (
    id TEXT PRIMARY KEY,
    recipient_email TEXT NOT NULL,
    subject TEXT NOT NULL,
    from_address TEXT NOT NULL,
    from_name TEXT,
    text_body TEXT,
    html_body TEXT,
    provider TEXT NOT NULL,
    metadata JSONB NOT NULL DEFAULT '{}',
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_emails_created_at ON emails (created_at DESC);

CREATE INDEX IF NOT EXISTS idx_emails_recipient_email ON emails (recipient_email);
