-- =============================================================================
-- SEED 010 — Planos e Preços
-- =============================================================================
-- Idempotente: ON CONFLICT (id) DO UPDATE
--
-- Planos:
--   patient_free     → pacientes (R$0)
--   therapist_free   → terapeutas solo (R$0)
--   therapist_pro    → terapeutas PRO (R$49/mês, R$490/ano)
--   clinic_free      → clínicas (R$0)
--   clinic_pro       → clínicas PRO (R$149/mês, R$1490/ano)
--   supervisor_free  → supervisores (R$0, até 3 supervisionados)
--   supervisor_pro   → supervisores PRO (R$0, até 20 supervisionados)
--
-- UUIDs preservados do data_dump original para consistência.
-- =============================================================================

BEGIN;

-- ============================================================
-- 1. Plans
-- ============================================================

INSERT INTO public.plans (id, key, name, description, is_active, created_at, price_cents, currency, billing_interval, target, max_supervisees)
VALUES
  ('984c1f29-a975-4208-93ac-2118ed1039b7', 'patient_free',    'Paciente Free',    'Plano gratuito para pacientes',                                                     true, '2026-03-03 22:40:11.413107+00', 0,     'BRL', 'month', 'patient',    NULL),
  ('c56fe2a8-2c17-4048-adc7-ff7fbd89461a', 'therapist_free',  'THERAPIST FREE',   'Plano gratuito para terapeutas.',                                                   true, '2026-03-01 09:40:48.439668+00', 0,     'BRL', 'month', 'therapist',  NULL),
  ('82067ba7-16f0-4803-b36f-4c4e8919d4b4', 'therapist_pro',   'THERAPIST PRO',    'Plano completo para terapeutas.',                                                   true, '2026-03-01 09:25:03.878498+00', 4900,  'BRL', 'month', 'therapist',  NULL),
  ('01a5867f-0705-4714-ac97-a23470949157', 'clinic_free',     'CLINIC FREE',      'Plano gratuito para clínicas iniciarem.',                                           true, '2026-03-01 09:25:03.878498+00', 0,     'BRL', 'month', 'clinic',     NULL),
  ('a74bc2d4-88c6-4cc6-b004-ef2bcb1b5145', 'clinic_pro',      'CLINIC PRO',       'Plano completo para clínicas.',                                                     true, '2026-03-01 09:30:06.50975+00',  14900, 'BRL', 'month', 'clinic',     NULL),
  ('8c4895a3-e12d-48de-a078-efb8a4ea2eb2', 'supervisor_free', 'Supervisor Free',  'Plano gratuito de supervisão. Até 3 terapeutas supervisionados.',                   true, '2026-03-05 00:58:17.218326+00', 0,     'BRL', 'month', 'supervisor', 3),
  ('ca28e46c-0687-45d5-9406-0a0f56a5b625', 'supervisor_pro',  'Supervisor PRO',   'Plano profissional de supervisão. Até 20 terapeutas supervisionados.',              true, '2026-03-05 00:58:17.218326+00', 0,     'BRL', 'month', 'supervisor', 20)
ON CONFLICT (id) DO UPDATE SET
  name             = EXCLUDED.name,
  description      = EXCLUDED.description,
  is_active        = EXCLUDED.is_active,
  price_cents      = EXCLUDED.price_cents,
  currency         = EXCLUDED.currency,
  billing_interval = EXCLUDED.billing_interval,
  max_supervisees  = EXCLUDED.max_supervisees;


-- ============================================================
-- 2. Plan Prices (somente planos pagos)
-- ============================================================

INSERT INTO public.plan_prices (id, plan_id, currency, "interval", amount_cents, is_active, active_from, active_to, source, provider, provider_price_id, created_at)
VALUES
  -- therapist_pro: R$49/mês
  ('37510504-4617-4421-9979-4249778bd5ae', '82067ba7-16f0-4803-b36f-4c4e8919d4b4', 'BRL', 'month', 4900,   true, '2026-03-01 09:25:03.878498+00', NULL, 'manual', NULL, NULL, '2026-03-01 09:25:03.878498+00'),
  -- therapist_pro: R$490/ano
  ('225afd5a-9f30-46bc-a0df-5eb8f91660cb', '82067ba7-16f0-4803-b36f-4c4e8919d4b4', 'BRL', 'year',  49000,  true, '2026-03-01 09:25:03.878498+00', NULL, 'manual', NULL, NULL, '2026-03-01 09:25:03.878498+00'),
  -- clinic_pro: R$149/mês
  ('124779b4-362d-4890-9631-747021ecc1c0', 'a74bc2d4-88c6-4cc6-b004-ef2bcb1b5145', 'BRL', 'month', 14900,  true, '2026-03-01 09:30:06.50975+00',  NULL, 'manual', NULL, NULL, '2026-03-01 09:30:06.50975+00'),
  -- clinic_pro: R$1490/ano
  ('73908784-6299-45c8-b547-e1556b45c292', 'a74bc2d4-88c6-4cc6-b004-ef2bcb1b5145', 'BRL', 'year',  149000, true, '2026-03-01 09:30:06.50975+00',  NULL, 'manual', NULL, NULL, '2026-03-01 09:30:06.50975+00')
ON CONFLICT (id) DO UPDATE SET
  amount_cents = EXCLUDED.amount_cents,
  is_active    = EXCLUDED.is_active,
  active_from  = EXCLUDED.active_from,
  active_to    = EXCLUDED.active_to;


-- ============================================================
-- 3. Confirma
-- ============================================================

DO $$
BEGIN
  RAISE NOTICE 'seed_010_plans: 7 planos e 4 preços inseridos/atualizados.';
END;
$$;

COMMIT;
