-- 005_attorney_review.sql
-- Attorney review add-on for compliance services (NOT formations).
-- Clients can optionally add attorney review to any compliance deliverable.

BEGIN;

-- Add attorney review fields to the general orders table (compliance services)
ALTER TABLE orders ADD COLUMN IF NOT EXISTS attorney_review_requested BOOLEAN DEFAULT FALSE;
ALTER TABLE orders ADD COLUMN IF NOT EXISTS attorney_review_status TEXT DEFAULT NULL
    CHECK (attorney_review_status IS NULL OR attorney_review_status IN (
        'pending', 'sent_to_attorney', 'in_review', 'completed', 'returned'
    ));
ALTER TABLE orders ADD COLUMN IF NOT EXISTS attorney_review_fee_cents INTEGER DEFAULT 0;
ALTER TABLE orders ADD COLUMN IF NOT EXISTS attorney_review_notes TEXT;
ALTER TABLE orders ADD COLUMN IF NOT EXISTS attorney_review_completed_at TIMESTAMPTZ;

-- Attorney review pricing per service type
CREATE TABLE IF NOT EXISTS attorney_review_pricing (
    id              SERIAL PRIMARY KEY,
    service_slug    TEXT NOT NULL UNIQUE,
    review_fee      INTEGER NOT NULL,       -- cents: what client pays
    attorney_cost   INTEGER NOT NULL,       -- cents: what we pay the attorney
    description     TEXT,
    available       BOOLEAN DEFAULT TRUE,
    created_at      TIMESTAMPTZ DEFAULT now()
);

INSERT INTO attorney_review_pricing (service_slug, review_fee, attorney_cost, description) VALUES
    ('flsa-audit',                69900, 45000, 'Attorney review of FLSA audit findings and remediation plan'),
    ('contractor-classification', 49900, 35000, 'Attorney legal opinion letter on contractor classification'),
    ('handbook-review',           69900, 50000, 'Attorney review of employee handbook compliance recommendations'),
    ('policy-development',        69900, 50000, 'Attorney review of custom workplace policies'),
    ('ccpa-audit',                69900, 45000, 'Attorney review of CCPA/CPRA audit findings'),
    ('privacy-policy',            39900, 30000, 'Attorney review of generated privacy policy'),
    ('data-mapping',              49900, 35000, 'Attorney review of data inventory and flow analysis'),
    ('breach-response',           69900, 45000, 'Attorney review of breach response plan'),
    ('consent-audit',             49900, 35000, 'Attorney review of TCPA consent practices assessment'),
    ('dnc-compliance',            39900, 25000, 'Attorney review of DNC compliance assessment'),
    ('campaign-review',           39900, 25000, 'Attorney review of marketing campaign compliance')
ON CONFLICT (service_slug) DO NOTHING;

COMMIT;
