-- STEP 1: Update program_type_v1 for PT_HDBMSD
UPDATE program_type_v1
SET
    involves_travel    = true,
    requires_residence = true,
    has_checkin_checkout = true,
    updated_at         = NOW()
WHERE key        = 'PT_HDBMSD'
  AND deleted_at IS NULL;

-- STEP 3: Update all HDBMSD programs (parent)
UPDATE program_v1
SET
    involves_travel    = true,
    requires_residence = true,
    has_checkin_checkout = true,
    updated_at         = NOW()
WHERE program_type_id = (SELECT id FROM program_type_v1 WHERE key = 'PT_HDBMSD')
  AND deleted_at IS NULL;

-- STEP 4: Update all sessions belonging to HDBMSD programs
UPDATE program_session
SET
    involves_travel    = true,
    requires_residence = true,
    has_checkin_checkout = true,
    updated_at         = NOW()
WHERE program_id IN (
    SELECT id FROM program_v1
    WHERE program_type_id = (SELECT id FROM program_type_v1 WHERE key = 'PT_HDBMSD')
      AND deleted_at IS NULL
)
  AND deleted_at IS NULL;

-- STEP 5: Add services_accounting_code (SAC) column to program type, program and session tables
ALTER TABLE program_type_v1
    ADD COLUMN IF NOT EXISTS services_accounting_code varchar(10);

ALTER TABLE program_v1
    ADD COLUMN IF NOT EXISTS services_accounting_code varchar(10);

ALTER TABLE program_session
    ADD COLUMN IF NOT EXISTS services_accounting_code varchar(10);

COMMENT ON COLUMN program_type_v1.services_accounting_code IS 'Services Accounting Code (SAC) for GST on services';
COMMENT ON COLUMN program_v1.services_accounting_code     IS 'Services Accounting Code (SAC) for GST on services';
COMMENT ON COLUMN program_session.services_accounting_code IS 'Services Accounting Code (SAC) for GST on services';
---- update the sac code for PT_TAT program type and its programs
select * from program_type_v1 where key = 'PT_TAT';
select * from program_v1 where program_type_id in (select id from program_type_v1 where key = 'PT_TAT');

update program_type_v1
set services_accounting_code = '999293'
where key = 'PT_TAT';

update program_v1
set services_accounting_code = '999293'
where program_type_id in (select id from program_type_v1 where key = 'PT_TAT');

select * from program_type_v1 where key = 'PT_TAT';

--- update to waitlist applicable
update program_type_v1
set waitlist_applicable = true,
max_capacity = 2000,
limited_seats = true
where key = 'PT_TAT';

--- update Email communications
update program_type_v1
set email_sender_name = 'TAT Online - infinitheism',
email_sender_address = 'events@infinitheism.com'
where key = 'PT_TAT';

--- update invoice
update program_type_v1
set invoice_sender_name = 'infinitheism spiritual foundation private limited',
invoice_sender_address = '3, 3rd Cross Road, R.A. Puram, Chennai 600 028, Tamil Nadu, India.',
invoice_sender_pan = 'AACCI7694H',
gst_number = '33AACCI7694H1ZB',
invoice_sender_cin = 'U74900TN2011PTC083263',
services_accounting_code = '999294'
where key = 'PT_TAT';

--- update helpline_number
update program_type_v1
set helpline_number = '+91-9841660000'
where key = 'PT_TAT';