-- Lets a product opt into an explicit set of supported platforms, each with
-- an optional claimable quota independent of how many keys actually exist
-- (e.g. 500 keys imported, only 200 claimable right now). No rows for a
-- product = unrestricted, same behavior as before this migration: every
-- configured platform shown, no quota cap -- existing products and claim
-- links keep working exactly as-is until an admin opts a product into this.

-- claim_limit is enforced against a live COUNT(*) of redeemed keys at claim
-- time (not a separately-maintained counter, so it can't drift), with this
-- row itself locked via SELECT ... FOR UPDATE to serialize concurrent
-- claims against the same product+platform quota -- same pattern as
-- claim_link_products.claims_used.
CREATE TABLE IF NOT EXISTS product_platforms (
    product_id  INT UNSIGNED NOT NULL,
    platform    VARCHAR(32) NOT NULL,
    claim_limit INT UNSIGNED NULL, -- NULL = unlimited (bounded only by actual key stock)
    PRIMARY KEY (product_id, platform),
    CONSTRAINT fk_pp_product FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE,
    CONSTRAINT fk_pp_platform FOREIGN KEY (platform) REFERENCES platforms(slug) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
