CREATE TABLE IF NOT EXISTS svg_asset_receipts (
    id BIGSERIAL PRIMARY KEY,
    tenant_key TEXT NOT NULL,
    receipt_id TEXT NOT NULL UNIQUE,
    asset_id TEXT NOT NULL,
    asset_type TEXT NOT NULL,
    theme TEXT NOT NULL,
    style TEXT NOT NULL,
    size INTEGER NOT NULL CHECK (size BETWEEN 32 AND 512),
    variant_count INTEGER NOT NULL CHECK (variant_count BETWEEN 1 AND 4),
    request_payload JSONB NOT NULL,
    result_payload JSONB NOT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS svg_asset_receipts_tenant_created_idx
    ON svg_asset_receipts (tenant_key, created_at DESC);

CREATE INDEX IF NOT EXISTS svg_asset_receipts_tenant_asset_idx
    ON svg_asset_receipts (tenant_key, asset_id);
