-- Deal/chop proposals table for tournament end-game scenarios.
-- Proposals are created, reviewed by the TD, then confirmed or cancelled.

CREATE TABLE IF NOT EXISTS deal_proposals (
    id TEXT PRIMARY KEY,
    tournament_id TEXT NOT NULL REFERENCES tournaments(id) ON DELETE CASCADE,
    deal_type TEXT NOT NULL CHECK (deal_type IN (
        'icm', 'chip_chop', 'even_chop', 'custom', 'partial_chop'
    )),
    payouts TEXT NOT NULL DEFAULT '[]',       -- JSON array of DealPayout
    total_amount INTEGER NOT NULL DEFAULT 0,  -- cents
    is_partial INTEGER NOT NULL DEFAULT 0,
    remaining_pool INTEGER NOT NULL DEFAULT 0, -- cents, for partial chop
    status TEXT NOT NULL DEFAULT 'proposed' CHECK (status IN (
        'proposed', 'confirmed', 'cancelled'
    )),
    created_at INTEGER NOT NULL DEFAULT (unixepoch())
);

CREATE INDEX IF NOT EXISTS idx_deal_proposals_tournament ON deal_proposals(tournament_id);
CREATE INDEX IF NOT EXISTS idx_deal_proposals_status ON deal_proposals(tournament_id, status);
