-- EXAMPLE ONLY. Replace placeholders. Run only in the NEW POS Supabase project.
-- Create a tenant after the owner has registered in Supabase Auth.
-- Never use this to modify the Smart Card database.

-- 1) Create shop:
insert into public.tenants (shop_code, shop_name, shop_type, currency_code)
values ('SHOP_A_CODE', 'Shop A Name', 'general', 'LKR')
returning id;

-- 2) Link the owner's Auth user ID to this tenant:
-- Replace TENANT_UUID and OWNER_AUTH_USER_UUID with real UUIDs.
insert into public.shop_members (tenant_id, user_id, role, is_active)
values ('TENANT_UUID', 'OWNER_AUTH_USER_UUID', 'owner', true);

-- 3) Do not insert WhatsApp access tokens here.
-- Store the token using Supabase Vault. Then insert/update shop_whatsapp_settings
-- with the returned Vault secret UUID:
-- insert into public.shop_whatsapp_settings
-- (tenant_id, enabled, recipient_phone, phone_number_id, waba_id,
--  access_token_secret_id, order_template_name, template_language)
-- values
-- ('TENANT_UUID', true, '9477XXXXXXX', 'META_PHONE_NUMBER_ID',
--  'META_WABA_ID', 'VAULT_SECRET_UUID', 'new_retail_order', 'en');
