-- Sensi AI request form: a phone-contact consent checkbox (Sensi's Growth Agent calls new leads automatically) and the
-- thank-you wording shown before the visitor is sent on to sensi.ai.
-- Idempotent and additive: the field is only added once, and the message is only replaced while it is still the original
-- wording, so anything staff edit later in ABOS > Website > Content > Forms is never overwritten.
-- Requires larcare_sensi_ai_form.sql first.

USE db_abos_v0.1;

SET @larcare_site_id = (SELECT id FROM dim_web_sites WHERE public_site_key = 'pSlfeq9OCm5MvZyoFguIK7jy0uz2aKShJkxZxTSWXwzPOpYJ' AND is_deleted = 0 LIMIT 1);
SET @sensi_id = (SELECT id FROM dim_web_forms WHERE site_id = @larcare_site_id AND form_key = 'sensi-ai-information' LIMIT 1);

INSERT INTO dim_web_form_fields (form_id, field_key, label, field_type, is_required, sort_order)
SELECT * FROM (SELECT @sensi_id AS a, 'phoneConsent' AS b, 'I agree to be contacted by phone, including by an AI assistant, about Sensi AI with LarCare Services.' AS c, 'checkbox' AS d, 1 AS e, 8 AS f) AS t
WHERE @sensi_id IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM dim_web_form_fields WHERE form_id = @sensi_id AND field_key = 'phoneConsent');

UPDATE dim_web_forms
   SET success_message = 'Thank you for your interest in Sensi AI with LarCare Services! Your information has been received. You will now be redirected to the official Sensi AI website to learn more.'
 WHERE id = @sensi_id
   AND success_message = 'Thank you. A LarCare representative will contact you with more information about Sensi AI, including availability, pricing and next steps.';
