-- ============================================================================
-- email_activity_proposals — the email-activity agent's PROPOSED grid notes,
-- queued for human review. The agent (local model, sovereign) drafts one note per
-- newly-matched email; a partner approves (optionally after editing) or dismisses
-- it in the web UI. Only on approval does the text get appended to the grid.
-- One proposal per email (email_id UNIQUE) — never re-proposed.
-- ============================================================================
CREATE TABLE IF NOT EXISTS email_activity_proposals (
    id            TEXT PRIMARY KEY,
    email_id      TEXT NOT NULL UNIQUE,
    investor_id   TEXT,                 -- fundraising_investors.id / grid row id (best-effort)
    investor_name TEXT,
    direction     TEXT,                 -- sent | received
    summary       TEXT,                 -- the one-line gist from the local model
    proposed_note TEXT,                 -- the full note as drafted (editable before approve)
    email_subject TEXT,                 -- context shown to the reviewer
    email_date    TEXT,
    status        TEXT NOT NULL DEFAULT 'pending',  -- pending | approved | dismissed
    decided_by    TEXT,                 -- users.id who approved/dismissed
    decided_at    TEXT,
    final_note    TEXT,                 -- the text actually appended on approval (may be edited)
    created_at    TEXT DEFAULT (datetime('now')),
    FOREIGN KEY(email_id) REFERENCES emails(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_email_proposals_status ON email_activity_proposals(status);
CREATE INDEX IF NOT EXISTS idx_email_proposals_investor ON email_activity_proposals(investor_id);
