-- =============================================================================
-- larcare_careers_apply_zoho.sql - job applications go to the Zoho form, not into Aggie. On the Careers page the
-- "Apply Now" buttons open the Zoho Contractor Application, and the on-site "Apply to Join Our Team" form is replaced
-- by a button to the same Zoho form. Changes the saved page only while its third section is still that form, so a page
-- someone has already edited is left alone. Safe to run again.
-- Requires 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 @c_page_content := (SELECT id FROM dim_web_collections WHERE site_id = @site_id AND collection_key = 'page-content' LIMIT 1);

UPDATE fact_web_entries
SET data_json = REPLACE(
      JSON_REPLACE(data_json, '$.sections[2]',
        JSON_OBJECT('type', 'cta', 'title', 'Apply to Join Our Team',
                    'text', 'Complete our application in Zoho Forms. A member of our team will be in touch within two business days.',
                    'primary', JSON_OBJECT('label', 'Start Your Application', 'href', 'https://zfrmz.com/YIU8x2sXbGi4hpGZdE5R'),
                    'phone', TRUE)),
      '"#applyForm"', '"https://zfrmz.com/YIU8x2sXbGi4hpGZdE5R"')
WHERE site_id = @site_id AND collection_id = @c_page_content AND slug = 'careers' AND is_deleted = 0 AND JSON_VALID(data_json)
  AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.sections[2].type')) = 'form'
  AND JSON_UNQUOTE(JSON_EXTRACT(data_json, '$.sections[2].formKey')) = 'careers-interest';
