-- =============================================================================
-- larcare_design_update_eligibility.sql - brings the LarCare CMS copy in line with the updated
-- reference design: "Welcome to Lar Care" hero with the eligibility call to action, the free care plan
-- band, simplified regions block. Existing values are only replaced while they still hold the previous
-- built-in text (so anything edited in ABOS > Website > Collections is left alone). Idempotent.
-- Requires seed_larcare_dynamic_design.sql first.
-- =============================================================================
SET @site_id := (SELECT id FROM dim_web_sites WHERE public_site_key = 'pSlfeq9OCm5MvZyoFguIK7jy0uz2aKShJkxZxTSWXwzPOpYJ' AND is_deleted = 0 LIMIT 1);
SET @tenant_id := (SELECT tenant_id FROM dim_web_sites WHERE id = @site_id LIMIT 1);
SET @business_id := (SELECT business_id FROM dim_web_sites WHERE id = @site_id LIMIT 1);
SET @c_design_settings := (SELECT id FROM dim_web_collections WHERE site_id = @site_id AND collection_key = 'design-settings' LIMIT 1);
SET @c_site_stats := (SELECT id FROM dim_web_collections WHERE site_id = @site_id AND collection_key = 'site-stats' LIMIT 1);
SET @c_coverage_plans := (SELECT id FROM dim_web_collections WHERE site_id = @site_id AND collection_key = 'coverage-plans' LIMIT 1);

UPDATE fact_web_entries SET data_json = '{"value": "Welcome to Lar Care"}' WHERE collection_id = @c_design_settings AND slug = 'hero-title' AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.value')) = 'Personal Home Care|for Every Unique [[Situation]]';
UPDATE fact_web_entries SET data_json = '{"value": "Larry puts the care in Lar Care"}' WHERE collection_id = @c_design_settings AND slug = 'hero-slogan' AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.value')) = '"Larry puts the care in LarCare"';
UPDATE fact_web_entries SET data_json = '{"value": "Request a Free Care Consultation"}' WHERE collection_id = @c_design_settings AND slug = 'hero-primary-label' AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.value')) = 'Request a free care consultation';
UPDATE fact_web_entries SET data_json = '{"value": "Check Your Potential Eligibility"}' WHERE collection_id = @c_design_settings AND slug = 'hero-secondary-label' AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.value')) = 'Verify Your Coverage';
UPDATE fact_web_entries SET data_json = '{"value": "/eligibility-screener"}' WHERE collection_id = @c_design_settings AND slug = 'hero-secondary-href' AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.value')) = '/about-us/contact-us';
UPDATE fact_web_entries SET data_json = '{"value": "Don''t let cost stand in the way of your quality care. Lar Care proudly serves clients covered by Medicaid, VA benefits, and most major private insurance plans."}' WHERE collection_id = @c_design_settings AND slug = 'coverage-text' AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.value')) = 'Don''t let cost stand in the way of quality care. LarCare proudly serves clients covered by Medicaid, VA benefits, and most major private insurance plans.';
UPDATE fact_web_entries SET data_json = '{"value": "Lar Care was named after Larry - a visionary who believes that care starts with the heart. We combine clinical excellence with genuine warmth, because great care is both professional and deeply human."}' WHERE collection_id = @c_design_settings AND slug = 'why-text' AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.value')) = 'LarCare was named after Larry — a visionary who believes that care starts at the heart. We combine clinical excellence with genuine warmth, because great care is both professional and deeply human.';
UPDATE fact_web_entries SET data_json = '{"value": "Regions Served"}' WHERE collection_id = @c_design_settings AND slug = 'locations-title' AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.value')) = 'We Serve Clients in 3 Regions';

INSERT INTO fact_web_entries (tenant_id, business_id, site_id, collection_id, slug, title, status, sort_order, data_json, created_by, updated_by, is_deleted)
SELECT @tenant_id, @business_id, @site_id, @c_design_settings, 'eligibility-cta-label', 'Eligibility button label', 'published', 40, '{"value": "Check Your Potential Eligibility →"}', NULL, NULL, 0 FROM DUAL
WHERE @c_design_settings IS NOT NULL AND NOT EXISTS (SELECT 1 FROM fact_web_entries WHERE collection_id = @c_design_settings AND slug = 'eligibility-cta-label');
INSERT INTO fact_web_entries (tenant_id, business_id, site_id, collection_id, slug, title, status, sort_order, data_json, created_by, updated_by, is_deleted)
SELECT @tenant_id, @business_id, @site_id, @c_design_settings, 'eligibility-cta-note', 'Eligibility button note', 'published', 41, '{"value": "Free, confidential, and takes less than one minute"}', NULL, NULL, 0 FROM DUAL
WHERE @c_design_settings IS NOT NULL AND NOT EXISTS (SELECT 1 FROM fact_web_entries WHERE collection_id = @c_design_settings AND slug = 'eligibility-cta-note');
INSERT INTO fact_web_entries (tenant_id, business_id, site_id, collection_id, slug, title, status, sort_order, data_json, created_by, updated_by, is_deleted)
SELECT @tenant_id, @business_id, @site_id, @c_design_settings, 'care-plan-eyebrow', 'Free care plan eyebrow', 'published', 42, '{"value": "No Cost to You"}', NULL, NULL, 0 FROM DUAL
WHERE @c_design_settings IS NOT NULL AND NOT EXISTS (SELECT 1 FROM fact_web_entries WHERE collection_id = @c_design_settings AND slug = 'care-plan-eyebrow');
INSERT INTO fact_web_entries (tenant_id, business_id, site_id, collection_id, slug, title, status, sort_order, data_json, created_by, updated_by, is_deleted)
SELECT @tenant_id, @business_id, @site_id, @c_design_settings, 'care-plan-title', 'Free care plan title', 'published', 43, '{"value": "Get Your Free Personalized Care Plan"}', NULL, NULL, 0 FROM DUAL
WHERE @c_design_settings IS NOT NULL AND NOT EXISTS (SELECT 1 FROM fact_web_entries WHERE collection_id = @c_design_settings AND slug = 'care-plan-title');
INSERT INTO fact_web_entries (tenant_id, business_id, site_id, collection_id, slug, title, status, sort_order, data_json, created_by, updated_by, is_deleted)
SELECT @tenant_id, @business_id, @site_id, @c_design_settings, 'care-plan-text', 'Free care plan text', 'published', 44, '{"value": "Our coordinators will assess your loved one''s unique needs and build a custom care plan at absolute no cost obligation. Start today and get back with the right services for your family''s fine."}', NULL, NULL, 0 FROM DUAL
WHERE @c_design_settings IS NOT NULL AND NOT EXISTS (SELECT 1 FROM fact_web_entries WHERE collection_id = @c_design_settings AND slug = 'care-plan-text');
INSERT INTO fact_web_entries (tenant_id, business_id, site_id, collection_id, slug, title, status, sort_order, data_json, created_by, updated_by, is_deleted)
SELECT @tenant_id, @business_id, @site_id, @c_design_settings, 'care-plan-button-label', 'Free care plan button label', 'published', 45, '{"value": "Request Your Free Care Plan →"}', NULL, NULL, 0 FROM DUAL
WHERE @c_design_settings IS NOT NULL AND NOT EXISTS (SELECT 1 FROM fact_web_entries WHERE collection_id = @c_design_settings AND slug = 'care-plan-button-label');
INSERT INTO fact_web_entries (tenant_id, business_id, site_id, collection_id, slug, title, status, sort_order, data_json, created_by, updated_by, is_deleted)
SELECT @tenant_id, @business_id, @site_id, @c_design_settings, 'care-plan-button-href', 'Free care plan button link', 'published', 46, '{"value": "/consultation"}', NULL, NULL, 0 FROM DUAL
WHERE @c_design_settings IS NOT NULL AND NOT EXISTS (SELECT 1 FROM fact_web_entries WHERE collection_id = @c_design_settings AND slug = 'care-plan-button-href');
INSERT INTO fact_web_entries (tenant_id, business_id, site_id, collection_id, slug, title, status, sort_order, data_json, created_by, updated_by, is_deleted)
SELECT @tenant_id, @business_id, @site_id, @c_design_settings, 'footer-fax', 'Footer fax line', 'published', 47, '{"value": "Fax: (804) 923-4384"}', NULL, NULL, 0 FROM DUAL
WHERE @c_design_settings IS NOT NULL AND NOT EXISTS (SELECT 1 FROM fact_web_entries WHERE collection_id = @c_design_settings AND slug = 'footer-fax');

UPDATE fact_web_entries SET title = 'Regions Served' WHERE collection_id = @c_site_stats AND slug = 'regions-served' AND is_deleted = 0 AND title = 'Regions served';
UPDATE fact_web_entries SET title = 'Years Combined Experience' WHERE collection_id = @c_site_stats AND slug = 'years-experience' AND is_deleted = 0 AND title = 'Years combined experience';
UPDATE fact_web_entries SET title = 'On-Call Support' WHERE collection_id = @c_site_stats AND slug = 'on-call-support' AND is_deleted = 0 AND title = 'On-call support';
UPDATE fact_web_entries SET title = 'Licensed & Bonded' WHERE collection_id = @c_site_stats AND slug = 'licensed-bonded' AND is_deleted = 0 AND title = 'Licensed & bonded';
UPDATE fact_web_entries SET data_json = JSON_SET(data_json, '$.description', REPLACE(JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.description')), 'LarCare', 'Lar Care')) WHERE collection_id = @c_coverage_plans AND slug IN ('veterans-benefits') AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.description')) LIKE 'We honor those who served. LarCare accepts%';
SET @c_featured_services := (SELECT id FROM dim_web_collections WHERE site_id = @site_id AND collection_key = 'featured-services' LIMIT 1);
UPDATE fact_web_entries SET data_json = JSON_SET(data_json, '$.href', '/healthcare#home-care') WHERE collection_id = @c_featured_services AND slug = 'home-care-services' AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.href')) = '/healthcare/home-and-personal-care-services';
UPDATE fact_web_entries SET data_json = JSON_SET(data_json, '$.href', '/healthcare#personal-care') WHERE collection_id = @c_featured_services AND slug = 'adult-child-personal-care' AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.href')) = '/healthcare';
UPDATE fact_web_entries SET data_json = JSON_SET(data_json, '$.href', '/healthcare#hospice') WHERE collection_id = @c_featured_services AND slug = 'luxury-hospice-respite' AND is_deleted = 0 AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.href')) = '/healthcare/end-of-life-care';
