-- 016: Breakage revenue records (clearing-service)
CREATE TABLE IF NOT EXISTS breakage_records (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    coupon_id UUID NOT NULL REFERENCES coupons(id),
    issuer_id UUID NOT NULL REFERENCES issuers(id),
    face_value NUMERIC(12,2) NOT NULL,
    total_amount NUMERIC(12,2) NOT NULL,
    platform_share NUMERIC(12,2) NOT NULL,
    issuer_share NUMERIC(12,2) NOT NULL,
    platform_share_rate NUMERIC(5,4) NOT NULL DEFAULT 0.1000,
    expired_at DATE NOT NULL,
    processed_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_breakage_coupon_id ON breakage_records(coupon_id);
CREATE INDEX idx_breakage_issuer_id ON breakage_records(issuer_id);
CREATE INDEX idx_breakage_expired_at ON breakage_records(expired_at);
