-- =====================================================
-- PT_ENTRAINMENT — Terms & Conditions content UPDATE (template_question + hdb_question)
-- 2026-08-11 (supersedes the 2026-08-10 draft below — placeholders now filled with the
-- finalized Entrainment 25 copy supplied by the business team)
-- DRAFT ONLY — not executed against any database, not yet reviewed/approved.
-- Updates label/question_text, question_type/typ (checkbox -> content — see WHY below), and
-- config (fully rebuilt, not merged). Idempotent (plain UPDATE ... SET, safe to re-run; no-op
-- wherever no matching row exists).
-- =====================================================
--
-- This is the finalized copy for the 'Entrainment 25' residential program (04–07 September
-- 2025, Leonia Holistic Destination, Hyderabad) — verbatim as supplied, not reworded. It
-- replaces the earlier structural draft (2026-08-10) that mirrored PT_PAP's/PT_TAT's clause
-- shape with '[TO BE UPDATED — ...]' placeholders for season-specific values; those are gone
-- now that the real dates/times/venue details are known. The consent-checkbox label is also
-- updated to the finalized wording (in-person communication + SMS/WhatsApp/Email/phone calls).
--
-- WHY question_type/typ ARE ALSO SET (unlike the PAP/TAT content-update scripts, which only
-- jsonb_set markdownContent): PT_ENTRAINMENT's 'terms' question was cloned VERBATIM from
-- master_question by STEP 8 of 06_ent_template.sql / 03template-refresh.sql (mq.question_type,
-- mq.config copied as-is), and master_question's 'terms' row inherited question_type='checkbox'
-- from hdb_question id 74 (typ='checkbox', see portal-base-master-data.sql:323) via the
-- hq.typ::question_type_enum cast in 01_master-data-migration.sql. PAP and TAT never hit this —
-- their own dedicated 'add terms question' scripts hardcode question_type='content' at INSERT
-- time instead of cloning master_question's type. So unlike PAP/TAT, Entrainment's row is still
-- a plain checkbox: setting only config.markdownContent has no visible effect, since the
-- frontend renders it as a checkbox and never reads markdownContent for that type. This script
-- fully rebuilds config to the same {type, contentFormat, isRequired, markdownContent} shape
-- PAP/TAT use (dropping the old checkbox-only keys like dependsOn/minCharacter/validationPattern,
-- which are meaningless for a content-type question) and flips question_type/typ to 'content'.
-- template_question.question_type is the real Postgres enum question_type_enum (has 'content',
-- added by 2026-06-09-03-add-content-question-type.sql); hdb_question.typ is a plain varchar
-- column (src/common/entities/question.entity.ts), so no enum-value check applies there.
--
-- master_question is NOT touched — 'terms' is a shared, global binding_key (see
-- database/base-script/portal-base-master-data.sql:323).
-- =====================================================
--update template_question tq
DO $$
DECLARE
    v_terms_label TEXT := 'I agree to receive information from infinitheism and hereby provide my consent to be contacted via in-person communication, SMS, WhatsApp, Email and phone calls. I have read,understood, provide my consent and agree to the above ‘Terms and conditions’.';
    v_terms_md    TEXT := E'\nFor the purposes of clarity, the term "**we/our/us/infinitheism**" refers to Infinitheism Spiritual Foundation Private Limited and the term "**you/your**" refers to the Participant of the Entrainment 26 ("**Program**").\n\n### A. General:\n\n1. The sessions will be conducted in English.\n\n2. Registration is on a first-come, first-served basis.\n\n3. Registration is confirmed only on receipt of a confirmation email from infinitheism upon completion of registration and realisation of full payment and subject to availability of seats.\n\n4. Registration is applicable for all participants who have completed 3 years of age, as on 03 September 2025.\n\n5. If you plan to bring your child below 3 years of age, please send an email to <a href="mailto:events@infinitheism.com" style="color: blue;">events@infinitheism.com</a> with details of your child.\n\n6. Parental consent is a must for participants who are below 18 years of age. The parental consent cum declaration form will be sent to the registered email address and will have to be signed by a parent/guardian and submitted to infinitheism on or before Thursday, 28 August 2025.\n\n7. **Program Venue: Leonia Holistic Destination**, Bommarasipet, Shamirpet Mandal, Medchal-Malkajgiri District, **Hyderabad** - 500078.\n\n8. The package includes accommodation on a double occupancy basis at Leonia Holistic Destination or at any other nearby resort, along with all meals, starting from High Tea on Thursday, 04 September and concluding with Lunch on Sunday, 07 September 2025, at Leonia resort.\n\n9. Any other additional expenses such as room service, laundry, or others services etc., are not included in the package and hence must be settled by the participant directly to Leonia or the other resort where the participant is accommodated.\n\n10. **Airport Pick-up Time:** Buses will be available at Hyderabad airport from **3:00 p.m. to 7:00 p.m.** on **Thursday, 04 September 2025.**\n\n11. **City Pick-up Time:** Buses will depart at **5:00 p.m.** from Ratnadeep, East Marredpally, Secunderabad on **Thursday, 04 September 2025.**\n\n12. **Check-in Time:** Check-in will be open from **4:00 p.m. to 9:00 p.m.** on **Thursday, 04 September 2025,** at Leonia**.**\n\n13. Travel duration from Hyderabad city/airport to Leonia Holistic Destination is approximately 90 minutes. Kindly plan your travel accordingly.\n\n14. Latecomers will not be allowed entry, even with a valid registration confirmation, immaterial of what the reasons may be, including force majeure (act of God, act of governmental body or military authority, fire, explosion, flood, epidemic, pandemic, government-imposed lockdown/closure of business, riot or civil disturbance, war, act of terrorism, sabotage, accidents, insurrections, blockades, embargoes, storms or similar event beyond the reasonable control) and no refund will be made at any point in time.\n\n15. **Check-out Time:** Participants must check out latest by **2:00 p.m.** on **Sunday, 07 September 2025.** We recommend outstation participants to plan their return journey departure post **4:00 p.m.** to have enough time to reach Hyderabad airport/city.\n\n16. Buses will depart from Leonia starting **11:45 a.m.** onwards on **Sunday, 07 September 2025**, in regular intervals to airport/Ratnadeep, East Marredpally, Secunderabad (City drop).\n\n17. Participants wishing to leave the premises earlier than the bus departure timings on the check-out date, are requested to make their own travel arrangements.\n\n18. If the registration is done by a person other than a participant (for and on behalf of a participant), it shall be the sole responsibility of such person to ensure that the participant is/has: (i) made aware of such registration, (ii) given his/her free consent; and (iii) informed about the terms and conditions of the program, etc. It is hereby clarified that neither infinitheism nor any of its directors, officers, permitted assigns, representatives etc., shall be held responsible for any claim made in this regard by any person (including but not limited to the participant) at any point in time.\n\n19. Children (and adults), causing disturbance, will be asked to leave the program.\n\n20. Request to transfer a registration from one participant to another, received on or before **Thursday, 28 August 2025**, will be considered at the sole discretion of the management of infinitheism.\n\n21. In the event a caretaker accompanies a participant to the program, regardless of whether the caretaker attends the sessions or not, the participant must register and make payment for the caretaker also.\n\n22. Smoking, consumption of alcohol, and chewing of tobacco are strictly prohibited within the premises.\n\n23. The overall room allocation for participants will be decided by the management of infinitheism. Strangers of opposite genders will not be accommodated in the same room.\n\n24. Usage of mobile phones or any other devices that may cause disturbances will not be allowed during the sessions.\n\n25. Recording the event in any form either audio, photography, or video, through mobile phone or camera is strictly prohibited.\n\n26. The management of Infinitheism reserves the right to deny entry and/or registration, without assigning any reason. Infinitheism will not be responsible for damage or loss of personal belongings and valuables of any Participant.\n\n### B. Cancellation and Refund Policy:\n\n27. Cancellation of registration and refund of the fee is governed as below:\n\n    <ol style="list-style-type: lower-alpha; margin-left: -20px; padding-left: 60px;">\n      <li style="margin-bottom: 8px;">Participants who want to cancel their registrations for whatever reason, are requested to send an email to <a href="mailto:events@infinitheism.com" style="color: blue;">events@infinitheism.com</a> from their registered email address, clearly mentioning their request for cancellation along with their name, mobile number and registration number.</li>\n      <li style="margin-bottom: 8px;">Cancellation requests received on or before <strong>Thursday, 28 August 2025</strong>, will be considered eligible for a refund of the amount paid. Cancellation requests received after this timeline or request of refund citing non-attendance due to late arrival and/ or whatever reason or leaving the venue before completion of the program (i.e before the check-out date), are not eligible for refund of amount paid, under any circumstances.</li>\n      <li style="margin-bottom: 8px;">Refunds will not be paid by cash irrespective of the mode of payment by the participant at the time of registration.</li>\n    </ol>\n\n### C. Collection and usage of personal information:\n\nYou consent to the collection, processing, storage, and use of your personal information by us, in accordance with the Digital Personal Data Protection Act, 2023 and other applicable laws of India. The Personal Information provided by you in connection with the Program to us will be used to send details and announcements related to the Program to you. Any personal information that you provide to us online will be handled only for legitimate purpose in accordance with the laws and regulations of India. We are committed to protecting your personal information and your right to privacy. Our <a href="https://www.infinitheism.com/privacy-policy/" target="_blank" rel="noopener noreferrer" style="color: blue;">''Privacy Policy''</a> and ''Terms &amp; Conditions'' govern the collection, storing, and processing of your information provided by you through our website. Please read our <a href="https://www.infinitheism.com/privacy-policy/" target="_blank" rel="noopener noreferrer" style="color: blue;">''Privacy Policy''</a> carefully as it will help you make informed decisions about sharing your personal information with us. If the participant is below 18 years of age, the parent/guardian of such participant shall be responsible for providing consent to the collection and usage of personal data/information of the said participant under this Clause. You retain the right to withdraw your consent at any time, without prejudice to the lawfulness of processing carried out prior to such withdrawal, and/or Access, correct, and erase your personal data. For any concerns or grievances related to the handling of your personal information, you may write to <a href="mailto:events@infinitheism.com" style="color: blue;">events@infinitheism.com</a>.\n\n28. **Limitation of liability:** Infinitheism''s liability for any accepted claim is limited to an aggregate maximum of the fee amount paid by the respective participant for all claims whatsoever. However, this clause is not applicable for claiming refund due to cancellation or non-attendance, which is specifically governed by ''cancellation and refund policy'' mentioned above.\n\n29. **Jurisdiction:** The provisions of this ''Terms and Conditions'' shall be governed by and construed in accordance with the laws of India, and subject to point 30 below, the parties shall submit to the exclusive jurisdiction of the courts at Chennai, India, in relation to any disputes arising under this document.\n\n30. **Disputes:**\n\n    30.1 In the event of any dispute, controversy or difference ("Dispute") of whatever nature, arising under, out of, in connection with, or relating to the enforcement, performance, or the terms and conditions of this document or any provision thereof, such Dispute shall be settled through good faith, negotiation amongst the parties to such Dispute.\n\n    30.2 In the event that such a Dispute cannot be resolved by negotiation within thirty (30) days of the Dispute has arisen, such Dispute shall be referred to binding arbitration and determined in accordance with the provisions of the Arbitration and Conciliation Act, 1996. The place of arbitration and the seat of arbitral proceedings shall be Chennai, India. Any arbitral proceeding begun pursuant to any reference made under this document shall be conducted in the English language. The decision of the arbitral tribunal and any award given by the majority of the arbitral tribunal shall be final and binding upon the parties.\n\n    30.3 Appointment of Arbitral Tribunal: The arbitral tribunal shall be composed of one sole arbitrator if the parties so agree. Failing such Agreement within a period of (10) days of the end of the conciliation process provided for in sub-clause (a) hereof, the arbitral tribunal shall comprise two arbitrators, one arbitrator shall be appointed by Infinitheism and one arbitrator shall be appointed by Participant and both such arbitrators shall appoint a Presiding Arbitrator in accordance with the provisions of Arbitration and Conciliation Act, 1996.\n\n    30.4 Conduct of Arbitral Proceedings: The parties, recognizing the necessity that any arbitral proceeding be concluded expeditiously, agree:\n\n    <ol style="list-style-type: lower-alpha; margin-left: -20px; padding-left: 60px;">\n      <li style="margin-bottom: 8px;">to carry out in full, promptly and without delay such procedural orders or directions as may be made by the arbitral tribunal from time to time.</li>\n      <li style="margin-bottom: 8px;">to carry out in full, promptly and without delay such interim measures of protection as may be ordered by the arbitral tribunal.</li>\n      <li style="margin-bottom: 8px;">to co-operate with each other and with the arbitral tribunal in the conduct of any arbitral proceeding with a view to enable the arbitral tribunal to conclude the proceeding (so far as may be practicable), by means of a final arbitral award within a period of 2 months from the date upon which recourse to arbitration was initiated by the service of a notice of arbitration.</li>\n      <li style="margin-bottom: 8px;">that questions of procedure may be decided by the Presiding arbitrator, as he or she deems fit, and that the presiding arbitrator is authorized accordingly.</li>\n      <li style="margin-bottom: 8px;">the arbitral tribunal may determine in their discretion, that (a) no oral hearing is held (unless it considers any such hearing to be either necessary or appropriate) and (b) accordingly any arbitral proceeding be conducted (in whole or in part) upon the basis of documents and other materials.</li>\n      <li style="margin-bottom: 8px;">The arbitral tribunal shall have the power to award costs to the parties.</li>\n    </ol>\n\n\n';
BEGIN
    -- 1) Entrainment templates
    UPDATE template_question tq
    SET question_text = v_terms_label,
        question_type = 'content',
        config        = jsonb_build_object(
                           'type',            'content',
                           'contentFormat',   'markdown',
                           'isRequired',      true,
                           'markdownContent', v_terms_md
                         ),
        updated_at    = NOW(),
        updated_by    = -2
    WHERE tq.binding_key = 'terms'
      AND tq.deleted_at IS NULL
      AND tq.template_form_section_id IN (
            SELECT tfs.id
            FROM template_form_section tfs
            JOIN program_template ptpl ON ptpl.id = tfs.program_template_id
            JOIN program_type_v1   pt  ON pt.id   = ptpl.program_type_id
            WHERE pt.key = 'PT_ENTRAINMENT' AND pt.deleted_at IS NULL
              AND ptpl.deleted_at IS NULL AND tfs.deleted_at IS NULL
      );

    -- 2) Entrainment program questions
    UPDATE hdb_question hq
    SET label      = v_terms_label,
        typ        = 'content',
        config     = jsonb_build_object(
                        'type',            'content',
                        'contentFormat',   'markdown',
                        'isRequired',      true,
                        'markdownContent', v_terms_md
                      ),
        updated_at = NOW(),
        updated_by = -2
    WHERE hq.binding_key = 'terms'
      AND hq.deleted_at IS NULL
      AND hq.id IN (
            SELECT hpq.question_id
            FROM hdb_program_question hpq
            JOIN program_v1      p  ON p.id  = hpq.program_id
            JOIN program_type_v1 pt ON pt.id = p.program_type_id
            WHERE pt.key = 'PT_ENTRAINMENT' AND pt.deleted_at IS NULL
              AND p.deleted_at IS NULL AND hpq.deleted_at IS NULL
      );
END $$;
