-- =====================================================
-- Update question LABELS for TAT (PT_TAT) only
--   1) template_question.question_text  (TAT templates)
--   2) hdb_question.label               (TAT program questions)
-- Labels only. Idempotent.
-- =====================================================

-- 1) TAT templates
UPDATE template_question tq
SET question_text = overrides.lbl,
    updated_at    = NOW(),
    updated_by    = -2
FROM (VALUES
    ('otherCityName',            'City name'),
    ('rmContact',                'Contact person at infinitheism'),
    ('otherInfinitheismContact', 'Other contact person'),
    ('profileUrl',               'Upload photo'),
    ('invoiceName',              'Name to be mentioned on the invoice'),
    ('invoiceEmail',             'Email address to which invoice to be sent'),
    ('isGstRegistered',          'Are you registered under India GST?'),
    ('invoiceAddress',           'Address to be mentioned on the invoice'),
    ('gstNumber',                'GSTIN to be mentioned on the invoice'),
    ('paymentMode',              'Choose your payment method*'),
    ('invoiceConfirmation',      'I have reviewed and confirm that my invoice information is correct and acknowledge that no changes will be permitted after submission.')
) AS overrides(bk, lbl)
WHERE tq.binding_key = overrides.bk
  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_TAT' AND pt.deleted_at IS NULL
          AND ptpl.deleted_at IS NULL AND tfs.deleted_at IS NULL
  );

-- 2) TAT program questions
UPDATE hdb_question hq
SET label      = overrides.lbl,
    updated_at = NOW(),
    updated_by = -2
FROM (VALUES
    ('otherCityName',            'City name'),
    ('rmContact',                'Contact person at infinitheism'),
    ('otherInfinitheismContact', 'Other contact person'),
    ('profileUrl',               'Upload photo'),
    ('invoiceName',              'Name to be mentioned on the invoice'),
    ('invoiceEmail',             'Email address to which invoice to be sent'),
    ('isGstRegistered',          'Are you registered under India GST?'),
    ('invoiceAddress',           'Address to be mentioned on the invoice'),
    ('gstNumber',                'GSTIN to be mentioned on the invoice'),
    ('paymentMode',              'Choose your payment method*'),
    ('invoiceConfirmation',      'I have reviewed and confirm that my invoice information is correct and acknowledge that no changes will be permitted after submission.')
) AS overrides(bk, lbl)
WHERE hq.binding_key = overrides.bk
  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_TAT' AND pt.deleted_at IS NULL
          AND p.deleted_at IS NULL AND hpq.deleted_at IS NULL
  );


-- =====================================================
-- 3) Update T&C (terms) content + consent label for PT_TAT
--    Applies to existing TAT templates AND TAT program questions.
--    Content/label mirror STEP 8 of 05_tat_template.sql.
-- =====================================================
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 ''This AND That (TAT) Online Live – Aug-2026'' (English) program (\"**Program**\").\n\n
I am enrolling myself in the Program conducted by infinitheism. The Program shall have 12 live online sessions of 2 hours each, as provided in the ''Program Schedule'' hereunder.

I understand, acknowledge and agree to the following ''Terms & Conditions'':

1. The medium of instruction for the Program shall be English.

2. By participating in the Program and accepting these ''Terms & Conditions'', the Participant is deemed to have voluntarily provided their clear, informed and unambiguous consent to participate in the Program.

3. 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, voluntary and clear consent; and (iii) informed about the ''Terms & Conditions'' of the Program. 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.

4. Participation in the Program is subject to prior registration and full payment of registration fees. infinitheism reserves the right to deny entry to and registration for the Program to any person, without assigning any reason therefor.

5. Eligibility: Only those individuals who have not previously experienced Higher Deeper Beyond (HDB) / My Sacred Days (MSD) programs conducted by infinitheism and those who have completed sixteen (16) years of age as on 03-Aug-2026 (the first session date), are eligible for registration in the Program.

6. A ''Parental Consent Declaration'' is compulsory for all Participants who are less than eighteen (18) years of age. The ''Parental Consent Declaration'' form is available on the registration portal accessible through infinitheism''s website and has also been sent to the Participant''s registered email address mentioned above.

   A scanned copy of the ''Parental Consent Declaration'' duly signed by the Participant''s parent/guardian must be submitted to infinitheism on or before 31st July, 2026 either by uploading the same on the registration portal or through email to ''<a href="mailto:events@infinitheism.com" style="color: blue;">events@infinitheism.com</a>'' from the Participant''s registered email address.

7. The ''Program Schedule'' is as follows:  
   **Dates:** August 3, 4, 5, 10, 11, 12, 17, 18, 19, 24, 25 & 26, 2026.  
   **Days:** Mondays, Tuesdays and Wednesdays.  
   **Session Time: 7:00 p.m. to 9:00 p.m. IST (2 hours).**

8. No Reminders relating to the ''Program Schedule'' shall be sent to the Participant and the Participant shall be responsible for keeping track of the dates and timings of the Program.

9. Late entry will not be allowed into the sessions, immaterial of whatever the reason may be. As no two watches show the same time, Participants are expected to log in to the online sessions of the Program by 6:45 p.m. IST.

10. 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.

11. I understand and agree that my eligibility to graduate as an ''infinitheist'' is subject to my attendance for all the sessions of the Program on time as provided herein.

12. By being absent or late to any one or more of the sessions of the Program, I understand and agree that I will not be allowed to attend that particular session(s) and also the last session, i.e., the 12th session of the Program on 26th August, 2026 and thus will not be eligible to graduate as an ''infinitheist''. Thereby, I will also not be eligible to attend any subsequent programs conducted by infinitheism exclusively for the ''infinitheist'' fraternity. However, I can attend the other sessions of this program.

13. 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.

14. 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.

15. Cancellation of registration for the Program and refund of the registration fee is governed as below;

    <ol style="list-style-type: lower-alpha; margin-left: -20px; padding-left: 20px;">
      <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 ''<a href="mailto:events@infinitheism.com" style="color: blue;">events@infinitheism.com</a>'', clearly mentioning their request for cancellation along with their name, mobile number and registration number.</li>
      <li style="margin-bottom: 8px;">Cancellation requests received from the Participants up until 31st July, 2026 IST, 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>
      <li style="margin-bottom: 8px;">Refunds will not be paid in cash irrespective of the mode of payment by the Participant at the time of registration.</li>
    </ol>

16. Recording, capturing, reproducing or storing the Program in any form (including audio, video, screen recording, screenshots or photograph) or through any device or means (including through mobile phones, laptops, tablets, computers, camera, software applications, technology or any other similar device or means) is strictly prohibited. However, infinitheism reserves its 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.

17. infinitheism is not responsible for any disruption in experiencing the Program due to any technical glitch, snag or other disturbances from the Participant''s side.

18. All contents of the Program remain the sole and exclusive intellectual property of infinitheism at all times and shall not be reproduced, assigned, licensed, recompiled, or reverse engineered without infinitheism''s written consent.

19. **Collection and usage of personal information:**

    <ol style="list-style-type: lower-alpha; margin-left: -20px; padding-left: 20px;">
      <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>
      <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>
      <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>
      <li style="margin-bottom: 8px;">If the Participant is below 18 years of age, the parent/guardian of such Participant shall have reviewed, understood, and consented to these ''Terms &amp; Conditions'' on behalf of the Participant, for the collection and usage of personal data/information of the said Participant as described herein, through the ''Parental Consent Declaration'' form mentioned under Clause 6.</li>
      <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 ''<a href="mailto:events@infinitheism.com" style="color: blue;">events@infinitheism.com</a>''.</li>
    </ol>

20. **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 15.

21. **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.

22. **Dispute Resolution:**

    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.

23. These ''Terms & Conditions'' constitute the entire agreement between the Parties. If any provision is invalid, the remainder shall continue in force.

    I hereby agree to receive communication from infinitheism through SMS, WhatsApp, email and phone calls or in any other form.
';
BEGIN
    -- TAT 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_TAT' AND pt.deleted_at IS NULL
              AND ptpl.deleted_at IS NULL AND tfs.deleted_at IS NULL
      );

    -- TAT 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_TAT' AND pt.deleted_at IS NULL
              AND p.deleted_at IS NULL AND hpq.deleted_at IS NULL
      );
END $$;


-- =====================================================
-- 4) Override profileUrl (Upload photo) isRequired -> false for PT_TAT
--    Applies to existing TAT templates AND TAT program questions.
--    Updates ONLY config.isRequired; rest of config untouched. Idempotent.
-- =====================================================

-- TAT templates
UPDATE template_question tq
SET config     = jsonb_set(COALESCE(tq.config, '{}'::jsonb), '{isRequired}', 'false'::jsonb),
    updated_at = NOW(),
    updated_by = -2
WHERE tq.binding_key = 'profileUrl'
  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_TAT' AND pt.deleted_at IS NULL
          AND ptpl.deleted_at IS NULL AND tfs.deleted_at IS NULL
  );

-- TAT program questions
UPDATE hdb_question hq
SET config     = jsonb_set(COALESCE(hq.config, '{}'::jsonb), '{isRequired}', 'false'::jsonb),
    updated_at = NOW(),
    updated_by = -2
WHERE hq.binding_key = 'profileUrl'
  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_TAT' AND pt.deleted_at IS NULL
          AND p.deleted_at IS NULL AND hpq.deleted_at IS NULL
  );


-- =====================================================
-- 5) Override isGstRegistered showDialog.dialogueContent for PT_TAT
--    Applies to existing TAT templates AND TAT program questions.
--    Updates ONLY config.showDialog.dialogueContent. Mirrors STEP 9 of
--    05_tat_template.sql. Idempotent.
-- =====================================================

-- TAT templates
UPDATE template_question tq
SET config     = jsonb_set(
                    tq.config,
                    '{showDialog,dialogueContent}',
                    to_jsonb('Important! If you do not provide your GSTIN, this transaction will be filed under ‘unregistered’ category in our GST return. This cannot be changed after submitting this form.'::text)
                 ),
    updated_at = NOW(),
    updated_by = -2
WHERE tq.binding_key = 'isGstRegistered'
  AND tq.deleted_at IS NULL
  AND tq.config ? 'showDialog'
  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_TAT' AND pt.deleted_at IS NULL
          AND ptpl.deleted_at IS NULL AND tfs.deleted_at IS NULL
  );

-- TAT program questions
UPDATE hdb_question hq
SET config     = jsonb_set(
                    hq.config,
                    '{showDialog,dialogueContent}',
                    to_jsonb('Important! If you do not provide your GSTIN, this transaction will be filed under ‘unregistered’ category in our GST return. This cannot be changed after submitting this form.'::text)
                 ),
    updated_at = NOW(),
    updated_by = -2
WHERE hq.binding_key = 'isGstRegistered'
  AND hq.deleted_at IS NULL
  AND hq.config ? 'showDialog'
  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_TAT' AND pt.deleted_at IS NULL
          AND p.deleted_at IS NULL AND hpq.deleted_at IS NULL
  );
