-- 036_customer_asset_manifest.sql
-- Immutable per-order UI asset snapshot.
--
-- customers.asset_version existed as a cache-buster / numeric marker, but it
-- does not freeze the actual S3 filenames used by an order. When OP2 moves to
-- dated assets, old orders must continue rendering with the asset names
-- captured at payment time.

ALTER TABLE customers
  ADD COLUMN IF NOT EXISTS asset_manifest jsonb;

COMMENT ON COLUMN customers.asset_manifest IS
  'Immutable UI asset manifest snapshot captured at order creation/payment. Rendering, decrypt, viewer, JPG and print should use this before latest S3 manifest.';

UPDATE customers
   SET asset_manifest = jsonb_build_object(
     'coverFrame', 'cover_frame.webp',
     'envelope',   'envelope.webp',
     'quill',      'quill.webp',
     'wax', jsonb_build_object(
       'crimson', 'wax_crimson.webp',
       'noir',    'wax_noir.webp',
       'gold',    'wax_gold.webp',
       'forest',  'wax_forest.webp'
     ),
     'signet', jsonb_build_object(
       'starpostPure', 'signet_starpost_pure.webp'
     ),
     'postcardBack', jsonb_build_object(
       'digital',  'postcard_back_digital.webp',
       'physical', 'postcard_back_template.webp'
     ),
     'botanicals', jsonb_build_object(
       'lavender',     'botanical_lavender.webp',
       'forgetMeNot',  'botanical_forget_me_not.webp',
       'fern',         'botanical_fern.webp',
       'pansy',        'botanical_pansy.webp',
       'eucalyptus',   'botanical_eucalyptus.webp',
       'daisy',        'botanical_daisy.webp',
       'maple',        'botanical_maple.webp',
       'delphinium',   'botanical_delphinium.webp',
       'ginkgo',       'botanical_ginkgo.webp',
       'hydrangea',    'botanical_hydrangea.webp'
     )
   )
 WHERE asset_manifest IS NULL;
