-- 023: Suspicious Activity Reports (compliance-service)
CREATE TABLE IF NOT EXISTS sar_reports (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    alert_id UUID REFERENCES aml_alerts(id),
    user_id UUID NOT NULL REFERENCES users(id),
    filing_type VARCHAR(20) NOT NULL DEFAULT 'initial' CHECK (filing_type IN ('initial', 'continuing', 'joint')),
    subject_info JSONB NOT NULL,
    suspicious_activity JSONB NOT NULL,
    total_amount NUMERIC(15,2),
    date_range_start DATE,
    date_range_end DATE,
    narrative TEXT,
    fincen_filing_id VARCHAR(50),
    status VARCHAR(20) NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'pending_review', 'filed', 'archived')),
    filed_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_sar_user_id ON sar_reports(user_id);
CREATE INDEX idx_sar_status ON sar_reports(status);
CREATE INDEX idx_sar_alert_id ON sar_reports(alert_id);
