-- =============================================================================
-- larcare_contact_states_only.sql - the Contact page, its consultation form and the footer show states and cities only:
--   1. The "Region" choice on the consultation form (also shown on the Consultation page and the location pages)
--      lists Virginia, South Carolina and US Virgin Islands instead of the individual towns and "Multiple Locations".
--   2. The three region cards on the Contact page lose their line of towns and areas (the card keeps the state name
--      and its link).
--   3. The footer's Contact column shows "Chester, SC" and "Hopewell, VA" instead of the full street addresses.
-- Each change applies only while the saved content still has the old towns, so anything edited afterwards in ABOS >
-- Website is never overwritten. Safe to run again. Requires larcare_forms_consultation_careers.sql and
-- larcare_page_content_seed.sql first.
-- =============================================================================
SET @site_id := (SELECT id FROM dim_web_sites WHERE public_site_key = 'pSlfeq9OCm5MvZyoFguIK7jy0uz2aKShJkxZxTSWXwzPOpYJ' AND is_deleted = 0 LIMIT 1);
SET @form_consultation := (SELECT id FROM dim_web_forms WHERE site_id = @site_id AND form_key = 'consultation' AND is_deleted = 0 LIMIT 1);
SET @c_page_content := (SELECT id FROM dim_web_collections WHERE site_id = @site_id AND collection_key = 'page-content' LIMIT 1);

UPDATE dim_web_form_fields
SET config_json = JSON_SET(config_json, '$.options', JSON_ARRAY('Virginia', 'South Carolina', 'US Virgin Islands'))
WHERE form_id = @form_consultation AND field_key = 'region' AND JSON_VALID(config_json)
  AND config_json LIKE '%Williamsburg%';

UPDATE fact_web_entries
SET data_json = JSON_SET(data_json,
      '$.sections[1].items[0].text', '', '$.sections[1].items[1].text', '', '$.sections[1].items[2].text', '')
WHERE site_id = @site_id AND collection_id = @c_page_content AND slug = 'contact' AND is_deleted = 0 AND JSON_VALID(data_json)
  AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.sections[1].type')) = 'regions'
  AND JSON_LENGTH(data_json, '$.sections[1].items') = 3
  AND (JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.sections[1].items[0].text')) LIKE '%Richmond%'
    OR JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.sections[1].items[1].text')) LIKE '%Columbia%'
    OR JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.sections[1].items[2].text')) LIKE '%St. Thomas%');

SET @c_design_settings := (SELECT id FROM dim_web_collections WHERE site_id = @site_id AND collection_key = 'design-settings' LIMIT 1);
UPDATE fact_web_entries SET data_json = JSON_SET(data_json, '$.value', 'Chester, SC')
WHERE site_id = @site_id AND collection_id = @c_design_settings AND slug = 'footer-address-1' AND is_deleted = 0 AND JSON_VALID(data_json)
  AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.value')) = '178 Columbia St, Chester, SC 29706';
UPDATE fact_web_entries SET data_json = JSON_SET(data_json, '$.value', 'Hopewell, VA')
WHERE site_id = @site_id AND collection_id = @c_design_settings AND slug = 'footer-address-2' AND is_deleted = 0 AND JSON_VALID(data_json)
  AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.value')) = '2304 Freeman St, Hopewell, VA 23860';
