-- Trinity Fencing: sync customers row to match the legacy HTML's current state.
--
-- Background: Trinity migrated route-wise (a Netlify redirect sends
-- /estimator/trinity-fencing/estimate.html -> /e/trinity-fencing). But the
-- pricing_json and branding_json on the customers row were never updated to
-- reflect the legacy HTML's current PRODUCTS / WARRANTY_BADGES / etc., so
-- /e/trinity-fencing has been rendering a stale version (10 products, 60 lbs
-- concrete, 15-year termite warranty, "galvanized steel posts" on metal-post
-- products) — exactly what Trey was complaining about.
--
-- This UPDATE mirrors every value from the current legacy HTML at
-- estimator/trinity-fencing/estimate.html into Trinity's customers row.
-- After it runs:
--
--   1. /e/trinity-fencing renders identically to the (redirected-away) legacy
--      page: 14 products including the 4 new 8 ft variants, 80 lbs concrete
--      footings, Postmaster metal-post specs, "Lifetime Workmanship & Labor
--      Warranty" badge, no 15-year termite warranty anywhere.
--   2. Trey can self-edit pricing via /my/updates (Phase 2 dashboard) since
--      the row now reflects the truth.
--   3. The legacy HTML file becomes redundant for serving (the redirect
--      already covered routing), but stays in the repo as a reference.
--
-- Idempotent: only touches business_name, branding_json, pricing_json. Status,
-- plan, ghl_webhook_url, stripe_customer_id, owner_user_id, slug, id, created_at
-- all preserved. Apply by pasting into Supabase SQL Editor.

-- ============================================================
-- STEP 0: Verify the trial row exists and matches expected shape.
-- ============================================================
select id, slug, status, business_name, plan, ghl_webhook_url is not null as has_webhook
  from public.customers
 where id = '19a2de54-7f21-4d08-937b-8d2e4c1a0b93';
-- Expected: 1 row with slug='trinity-fencing'.

-- ============================================================
-- STEP 1: UPDATE — sync pricing_json + branding_json from the legacy HTML.
-- ============================================================
update public.customers
   set business_name = 'Trinity Fencing',
       branding_json = '{
         "company_name":      "Trinity Fencing",
         "company_phone":     "2253350288",
         "company_email":     "jackhardesty@trinityfencingcompany.com",
         "service_area":      "Ascension Parish Louisiana",
         "notify_email":      "jackhardesty@trinityfencingcompany.com",
         "notify_phone":      "2253350288",
         "brand_color":       "#2A4333",
         "brand_color_light": "#47704F",
         "logo_url":          "/estimator/trinity-fencing/Logo.webp",
         "logo_style":        "height:28px;display:block",
         "warranty_badges":   ["Lifetime Workmanship & Labor Warranty", "Licensed & Insured", "Free On-Site Quotes"],
         "crm": {"type": "none", "endpoint": "https://app.jobnimbus.com/api1/contacts", "api_key": ""}
       }'::jsonb,
       pricing_json  = '{
         "prices": {
           "pine":          {"lo": 20, "hi": 22},
           "pine8":         {"lo": 30, "hi": 33},
           "cedar":         {"lo": 22, "hi": 24},
           "cedar8":        {"lo": 33, "hi": 36},
           "pine_metal":    {"lo": 22, "hi": 24},
           "pine_metal8":   {"lo": 33, "hi": 36},
           "cedar_metal":   {"lo": 24, "hi": 26},
           "cedar_metal8":  {"lo": 36, "hi": 39},
           "chainlink4":    {"lo": 20, "hi": 22},
           "chainlink5":    {"lo": 22, "hi": 24},
           "alum4":         {"lo": 40, "hi": 42},
           "alum5":         {"lo": 42, "hi": 44},
           "vinyl6":        {"lo": 42, "hi": 44},
           "vinyl8":        {"lo": 55, "hi": 60}
         },
         "gate_cost":     400,
         "gate_double":   700,
         "teardown_rate": 3.5,
         "min_ft":        50,
         "min_fee":       500,
         "h_mult":        {"4": 0.85, "6": 1.0, "8": 1.5},
         "products": [
           {"key": "pine",          "name": "Wood 6'' Pine Privacy (4x4 Posts)",   "desc": "Pressure-treated pine boards with wooden posts. Budget-friendly full privacy.",       "badge": "Most popular",            "enabled": true, "specs": ["4x4 pressure-treated pine posts", "Posts set 28\" deep in concrete", "80 lbs concrete footings", "6 ft tall", "Termite & rot resistant"]},
           {"key": "pine8",         "name": "Wood 8'' Pine Privacy (4x4 Posts)",   "desc": "Pressure-treated pine at 8 ft. Maximum privacy with wooden posts.",                   "badge": "Tallest pine",            "enabled": true, "specs": ["4x4 pressure-treated pine posts", "Posts set 28\" deep in concrete", "80 lbs concrete footings", "8 ft tall", "Termite & rot resistant"]},
           {"key": "cedar",         "name": "Wood 6'' Cedar Privacy (4x4 Posts)",  "desc": "Premium cedar boards with wooden posts. Naturally rot-resistant.",                    "badge": "",                        "enabled": true, "specs": ["4x4 wooden posts", "Posts set 28\" deep in concrete", "80 lbs concrete footings", "6 ft tall", "Naturally rot-resistant cedar"]},
           {"key": "cedar8",        "name": "Wood 8'' Cedar Privacy (4x4 Posts)",  "desc": "Premium cedar at 8 ft. Tallest natural-wood privacy with wooden posts.",              "badge": "",                        "enabled": true, "specs": ["4x4 wooden posts", "Posts set 28\" deep in concrete", "80 lbs concrete footings", "8 ft tall", "Naturally rot-resistant cedar"]},
           {"key": "pine_metal",    "name": "Wood 6'' Pine Privacy (Metal Posts)", "desc": "Pressure-treated pine boards with Postmaster metal posts. No concrete needed.",       "badge": "Upgraded posts",          "enabled": true, "specs": ["Postmaster Metal Posts", "No concrete needed - driven 4 ft into ground", "Rated for 80 mph winds", "Lifetime warranty on posts", "Pressure-treated pine boards", "6 ft tall"]},
           {"key": "pine_metal8",   "name": "Wood 8'' Pine Privacy (Metal Posts)", "desc": "Pressure-treated pine at 8 ft with Postmaster metal posts. No concrete needed.",     "badge": "Tallest metal-post pine", "enabled": true, "specs": ["Postmaster Metal Posts", "No concrete needed - driven 4 ft into ground", "Rated for 80 mph winds", "Lifetime warranty on posts", "Pressure-treated pine boards", "8 ft tall"]},
           {"key": "cedar_metal",   "name": "Wood 6'' Cedar Privacy (Metal Posts)","desc": "Premium cedar boards with Postmaster metal posts. Top-tier wood privacy.",            "badge": "Premium",                 "enabled": true, "specs": ["Postmaster Metal Posts", "No concrete needed - driven 4 ft into ground", "Rated for 80 mph winds", "Lifetime warranty on posts", "Naturally rot-resistant cedar", "6 ft tall"]},
           {"key": "cedar_metal8",  "name": "Wood 8'' Cedar Privacy (Metal Posts)","desc": "Premium cedar at 8 ft with Postmaster metal posts. Top-tier 8 ft wood privacy.",      "badge": "Top tier",                "enabled": true, "specs": ["Postmaster Metal Posts", "No concrete needed - driven 4 ft into ground", "Rated for 80 mph winds", "Lifetime warranty on posts", "Naturally rot-resistant cedar", "8 ft tall"]},
           {"key": "chainlink4",    "name": "Chainlink 4'' Galvanized",            "desc": "Durable galvanized steel. Best value for large areas at 4 ft tall.",                  "badge": "",                        "enabled": true, "specs": ["Heavy gauge galvanized steel", "Posts set 28\" deep in concrete", "80 lbs concrete footings", "4 ft tall"]},
           {"key": "chainlink5",    "name": "Chainlink 5'' Galvanized",            "desc": "Durable galvanized steel. Extra foot of height for added security.",                  "badge": "",                        "enabled": true, "specs": ["Heavy gauge galvanized steel", "Posts set 28\" deep in concrete", "80 lbs concrete footings", "5 ft tall"]},
           {"key": "alum4",         "name": "Aluminum 4''",                        "desc": "Elegant 4 ft aluminum. Pool-code compliant. Rust-free powder-coated.",                "badge": "Pool friendly",           "enabled": true, "specs": ["Powder-coated aluminum", "Pool-code compliant at 4 ft", "Posts set 28\" deep in concrete", "Rust-free and maintenance-free"]},
           {"key": "alum5",         "name": "Aluminum 5''",                        "desc": "Elegant 5 ft aluminum. Rust-free powder-coated for long life.",                       "badge": "",                        "enabled": true, "specs": ["Powder-coated aluminum", "5 ft tall", "Posts set 28\" deep in concrete", "Rust-free and maintenance-free"]},
           {"key": "vinyl6",        "name": "Vinyl 6''",                           "desc": "Never rots or splits. No painting needed. Full privacy at 6 ft.",                     "badge": "Low maintenance",         "enabled": true, "specs": ["UV-resistant PVC", "Posts set 28\" deep in concrete", "80 lbs concrete footings", "6 ft tall", "No painting or staining ever needed", "20+ year lifespan"]},
           {"key": "vinyl8",        "name": "Vinyl 8''",                           "desc": "Never rots or splits. Tallest vinyl privacy - 8 ft of uninterrupted privacy.",         "badge": "Tallest privacy",         "enabled": true, "specs": ["UV-resistant PVC", "Posts set 28\" deep in concrete", "80 lbs concrete footings", "8 ft tall", "No painting or staining ever needed", "20+ year lifespan"]}
         ]
       }'::jsonb
 where id   = '19a2de54-7f21-4d08-937b-8d2e4c1a0b93'
   and slug = 'trinity-fencing';
-- Expected: UPDATE 1.

-- ============================================================
-- STEP 2: Confirm the row reflects the new state.
-- ============================================================
-- select id, slug, status, business_name,
--        jsonb_array_length(pricing_json->'products') as product_count,
--        branding_json->'warranty_badges'->>0          as first_warranty_badge,
--        pricing_json->'prices'->'pine8'->'lo'         as pine8_lo
--   from public.customers
--  where id = '19a2de54-7f21-4d08-937b-8d2e4c1a0b93';
-- Expected: product_count=14, first_warranty_badge='Lifetime Workmanship & Labor Warranty', pine8_lo=30.
