-- =====================================================
-- PT_PAP — Terms & Conditions content UPDATE (template_question + hdb_question)
-- 2026-08-08
-- DRAFT ONLY — not executed against any database, not yet reviewed/approved.
-- Config only (label + config.markdownContent). Idempotent (plain UPDATE ... SET, safe to
-- re-run; no-op wherever no matching row exists).
-- =====================================================
--
-- Companion to database/migrations/2026-08-08-03-pt-pap-terms-conditions-question-add.sql,
-- which INSERTs the 'terms' template_question row (its own header explains why it doesn't
-- also touch hdb_question: no PT_PAP program exists yet to have one). This file is a
-- standalone UPDATE-only safety net for the exact same content, kept separate from 03's
-- one-time INSERT for the same reason 06_tat_label_overrides_update.sql is kept separate from
-- 05_tat_template.sql — so the content can be (re-)applied on its own later (e.g. after a
-- future copy revision) without re-running the guarded INSERT:
--   1) template_question — re-applies the same label/markdownContent 03 already inserted.
--      A true no-op today against a freshly-run 03 (content already matches), but this is the
--      script to touch if the copy changes again later, so it doesn't require re-diffing 03.
--   2) hdb_question — expected to affect 0 rows today, same "no PT_PAP program exists yet"
--      reason as 03's header — but included so a future PT_PAP program's cloned 'terms' row
--      gets the exact same content applied, same forward-compatible pattern already used for
--      2026-08-08-04's organisationName/organisationDescription hdb_question blocks and
--      2026-08-08-08's paymentMode hdb_question block.
--
-- Label/content are copied verbatim from 03's current v_terms_label/v_terms_md.
-- master_question is NOT touched — 'terms' is a shared, global binding_key (see
-- database/base-script/portal-base-master-data.sql:323).
-- =====================================================

DO $$
DECLARE
    v_terms_label TEXT := ' I have read and agree to all the above ‘Terms & Conditions’. ';
    v_terms_md    TEXT := E'For the purpose of clarity, the term "**infinitheism**" refers to "**Infinitheism Spiritual Foundation Private Limited**" and the term "**I/me/my/myself/Participant**" refers to the person enrolled in the ''Profit And Peace (PAP) Sep-2026'' residential training program. ("**Program**").\n\nI understand, acknowledge and agree to the following ''Terms & Conditions'':\n\n1. By participating in the program and accepting these ''Terms & Conditions'', through the online registration, the Participant is deemed to have voluntarily provided their clear, informed and unambiguous consent to adhere to these ''Terms & Conditions'' of this Program.\n\n2. The medium of instruction for the program shall be English.\n\n3. The ''Program Schedule'' is as follows:  \n   **Dates**: September 28, 29 & 30, 2026.  \n   **Days**: Monday, Tuesday and Wednesday.  \n   **Check-in time**: Monday, 28 September 2026, from 1:00 p.m. to 3:00 p.m.  \n   **Check-out time**: Wednesday, 30 September 2026, from 11:30 a.m. to 1:00 p.m.  \n   **Venue**: Radisson Blu Resort Temple Bay, 57, covelong Road, Mamallapuram, Tamil Nadu – 603104.\n\n4. Participation in the Program is subject to prior registration, seat offer by infinitheism and completion of full payment of the total amount. infinitheism reserves the right to deny entry to and registration for the Program to any person, without assigning any reason therefor.\n\n5. The Program package includes 2 nights accommodation on a single occupancy basis at the above venue, including all meals starting from high tea on 28 September 2026 to lunch on 30 September 2026. Room preference or room change request will not be entertained. Room allotted by infinitheism will be final.\n\n6. Any other expenses incurred by the participant apart from what is provided in the program package will have to be settled by the participant directly to the resort.\n\n7. Latecomers will not be allowed, immaterial of whatever the reasons may be. The participant is expected to check-in well before 3:00 p.m.\n\n8. Me being late or absent to any session, immaterial of what the reasons may be, including force majeure reasons which include but is not limited to acts of god, acts of nature, acts of war, act of governmental body or military authority, functions in the family, illness, network disruption, any other technological snags, fire, insurrection, explosion, flood, storm, pandemic, epidemic, terrorist action, sabotage, accidents, civil unrest or disturbances, embargos, riots, strikes, or any other similar event which is beyond reasonable control will not be allowed under any circumstances.\n\n9. It is mandatory for the participant to attend all sessions.\n\n10. The dress code will be formals / smart casuals; also carry comfortable clothing.\n\n11. Smoking and consumption of alcohol are strictly prohibited within the premises.\n\n12. Usage of mobile phones or any other devices causing disturbances will not be allowed during the sessions.\n\n13. Recording the event in any form (audio or video) and photography (mobile or camera) is strictly prohibited. However, infinitheism reserves the right to record the Program for its internal/business purposes. Participants consent to the use of their image and likeness for promotional purposes by accepting the terms contained herein.\n\n14. The participant will not be allowed to leave the hall, during the sessions.\n\n15. Any kind of disturbances, misconduct or distractions will not be allowed during the sessions. infinitheism reserves the right to remove any Participant from the session for misconduct, causing disturbances or distractions, even if the Participant has a valid registration. The Participant shall not be entitled to any refund in such a case.\n\n16. Transfer of registration fee from one Participant to another, if requested before the commencement of the Program, shall be at the sole discretion of infinitheism. All registrations and the fees paid are non-transferable unless otherwise permitted by infinitheism under this Clause.\n\n17. Cancellation of registration for the Program and refund of the registration 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 from their registered email address to ''events@infinitheism.com'', 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 from the Participants up until 25 September 2026, will be eligible for a refund of the amount paid by the Participant. Cancellation requests received after the above timeline or a request for refund citing non-attendance due to late entry or whatever reason are not entitled or eligible for a refund of the amount paid, under any circumstances.</li>\n      <li style="margin-bottom: 8px;">Refunds will not be paid in cash.</li>\n    </ol>\n\n18. All contents of the Program always remain the sole and exclusive intellectual property of infinitheism and shall not be reproduced, assigned, licensed, recompiled, or reverse engineered without infinitheism''s written consent.\n\n19. **Collection and usage of personal information:**\n\n    <ol style="list-style-type: lower-alpha; margin-left: -20px; padding-left: 60px;">\n      <li style="margin-bottom: 8px;">I consent to the collection, processing, storage, and use of my personal data by infinitheism, in accordance with the applicable laws of India which is inclusive of the Digital Personal Data Protection Act, 2023 and the Information Technology Act, 2000 as amended from time to time and the rules therein.</li>\n      <li style="margin-bottom: 8px;">The personal data provided by the Participant in connection with the Program to infinitheism will be solely used to send details and announcements related to the Program to the Participant. In addition, the Participant consents to receive information regarding any future programs conducted by infinitheism. For the avoidance of doubt, the consent obtained herein in relation to future programs is limited to providing information regarding the existence and happening of such future programs, and a separate consent shall be obtained from the Participant before sending any further details, updates or announcements relating to such future programs. Further, the Participant retains the right to withdraw their consent at any time in relation to receiving information regarding future programs conducted by infinitheism. Any personal data that the Participant provides to infinitheism will be handled only for lawful and legitimate purpose in accordance with applicable laws of India. infinitheism is committed to protecting the Participant''s personal data, and the Participant''s right to privacy. infinitheism''s <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 the information provided by the Participant.</li>\n      <li style="margin-bottom: 8px;">I acknowledge that I have read infinitheism''s <a href="https://www.infinitheism.com/privacy-policy/" target="_blank" rel="noopener noreferrer" style="color: blue;">''Privacy Policy''</a> carefully and it has helped me make informed decisions about sharing my personal information with infinitheism.</li>\n      <li style="margin-bottom: 8px;">For any concerns or grievances related to the handling of the Participant''s personal data, the Participant may write to the email address ''events@infinitheism.com''.</li>\n    </ol>\n\n20. **Limitation of Liability**: The liability of infinitheism is limited to an aggregate maximum of registration fee for any and all accepted claims. However, this Clause is not applicable for claiming a refund of registration fee due to cancellation of registration or non-attendance or late coming, which is specifically governed by Clause 17.\n\n21. **Governing Law and Jurisdiction**: The provisions of this ''Terms & Conditions'' shall be governed by and construed in accordance with the laws of India, and subject to Clause 22 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\n22. **Dispute Resolution**:\n\n    All disputes, differences and/or claims arising out of these ''Terms & Conditions'' whether during its subsistence or thereafter shall be settled through negotiation between the authorized representatives of the Parties. On failure of resolution through negotiation within 30 (thirty) days of initiation of negotiations, the Parties shall resolve the same through arbitration in accordance with the provisions of the Arbitration and Conciliation Act, 1996 and any statutory amendments thereto. The arbitration shall be conducted by an independent sole arbitrator appointed by mutual consent of the Parties. The arbitral award rendered by the arbitrator shall be final and binding upon the Parties and may be enforced through any court of competent jurisdiction. The seat and venue of arbitration shall be at Chennai, India. The arbitration proceedings shall be conducted in the English language.\n\n23. These ''Terms & Conditions'' constitute the entire agreement between the Parties. If any provision is invalid, the remainder shall continue in force.\n\nI hereby agree to receive communication from infinitheism through SMS, WhatsApp, email\nand phone calls or in any other form.\n';
BEGIN
    -- 1) PAP templates
    UPDATE template_question tq
    SET question_text = v_terms_label,
        config        = jsonb_set(COALESCE(tq.config, '{}'::jsonb), '{markdownContent}', to_jsonb(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_PAP' AND pt.deleted_at IS NULL
              AND ptpl.deleted_at IS NULL AND tfs.deleted_at IS NULL
      );

    -- 2) PAP program questions
    UPDATE hdb_question hq
    SET label      = v_terms_label,
        config     = jsonb_set(COALESCE(hq.config, '{}'::jsonb), '{markdownContent}', to_jsonb(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_PAP' AND pt.deleted_at IS NULL
              AND p.deleted_at IS NULL AND hpq.deleted_at IS NULL
      );
END $$;
