-- =====================================================================
-- configure-tenant-phase2.sql — set business hours + SMS copy for an
-- existing tenant (Phase 2)
--
-- Usage:
--   1. Edit @tenant_id and the JSON values below.
--   2. Run: mysql -h <db_host> -u <user> -p ai_front_desk < configure-tenant-phase2.sql
--
-- Leaving business_hours NULL (i.e. never running this script) means
-- hours are NOT enforced for that tenant — bookAppointment only checks
-- for double-booking, and the office_hours business rule trigger never
-- matches. That's a safe default for a tenant mid-onboarding, not an
-- error state.
--
-- Leaving sms_templates NULL (or omitting a key) falls back to the
-- built-in default copy in TenantRepository::DEFAULT_SMS_TEMPLATES.
-- =====================================================================

USE ai_front_desk;

SET @tenant_id = 1; -- change me

SET @business_hours = JSON_OBJECT(
    'mon', JSON_OBJECT('open', '09:00', 'close', '17:00'),
    'tue', JSON_OBJECT('open', '09:00', 'close', '17:00'),
    'wed', JSON_OBJECT('open', '09:00', 'close', '17:00'),
    'thu', JSON_OBJECT('open', '09:00', 'close', '17:00'),
    'fri', JSON_OBJECT('open', '09:00', 'close', '17:00'),
    'sat', CAST(NULL AS JSON),
    'sun', CAST(NULL AS JSON)
);

SET @sms_templates = JSON_OBJECT(
    'appointment_confirmation',
        'Hi {caller_name}, this confirms your appointment with {business_name} on {date} at {time}. Reply STOP to opt out of texts.',
    'missed_call',
        'Hi, sorry we missed your call to {business_name}. We will follow up with you shortly. Reply STOP to opt out of texts.'
);

UPDATE tenants
SET business_hours = @business_hours,
    sms_templates  = @sms_templates,
    updated_at     = NOW()
WHERE id = @tenant_id;

SELECT id, business_name, business_hours, sms_templates FROM tenants WHERE id = @tenant_id;
