-- +goose Up
INSERT INTO tenants (
  id, slug, name, preset, locale, timezone, plan_code, subscription_status
) VALUES (
  '5d6b3551-0a3e-4b86-bdf0-e9df20a47148',
  'studio-atelier',
  'Studio Atelier',
  'studio',
  'cs',
  'Europe/Prague',
  'pro',
  'active'
)
ON CONFLICT (id) DO NOTHING;

INSERT INTO users (id, email, display_name)
VALUES (
  '11111111-1111-1111-1111-111111111111',
  'owner@bookra.dev',
  'Bookra Demo Owner'
)
ON CONFLICT (id) DO NOTHING;

INSERT INTO tenant_users (tenant_id, user_id, role)
VALUES (
  '5d6b3551-0a3e-4b86-bdf0-e9df20a47148',
  '11111111-1111-1111-1111-111111111111',
  'owner'
)
ON CONFLICT (tenant_id, user_id) DO NOTHING;

INSERT INTO locations (id, tenant_id, name, timezone)
VALUES (
  '659f1cc0-a850-46d6-b3b8-cb15d55d8daf',
  '5d6b3551-0a3e-4b86-bdf0-e9df20a47148',
  'Prague Studio',
  'Europe/Prague'
)
ON CONFLICT (id) DO NOTHING;

INSERT INTO staff (id, tenant_id, location_id, display_name)
VALUES (
  '6936c444-c7d0-4a7d-b596-a9b72d2f4fc0',
  '5d6b3551-0a3e-4b86-bdf0-e9df20a47148',
  '659f1cc0-a850-46d6-b3b8-cb15d55d8daf',
  'Lenka Atelier'
)
ON CONFLICT (id) DO NOTHING;

INSERT INTO services (id, tenant_id, name, duration_minutes, buffer_before_minutes, buffer_after_minutes, price_cents)
VALUES (
  'd5d76a61-3d49-467c-8dd4-bf61ee754e39',
  '5d6b3551-0a3e-4b86-bdf0-e9df20a47148',
  'Signature treatment',
  60,
  0,
  15,
  120000
)
ON CONFLICT (id) DO NOTHING;

INSERT INTO class_templates (id, tenant_id, title, duration_minutes, capacity)
VALUES (
  'd13fe5fd-727f-4d69-bfd8-47f1b92a2cf7',
  '5d6b3551-0a3e-4b86-bdf0-e9df20a47148',
  'Small group mobility class',
  60,
  4
)
ON CONFLICT (id) DO NOTHING;

INSERT INTO class_sessions (id, tenant_id, template_id, location_id, starts_at, ends_at, capacity)
VALUES (
  '4bf74c12-44dd-45ca-86bb-b104f16f2435',
  '5d6b3551-0a3e-4b86-bdf0-e9df20a47148',
  'd13fe5fd-727f-4d69-bfd8-47f1b92a2cf7',
  '659f1cc0-a850-46d6-b3b8-cb15d55d8daf',
  now() + interval '2 days',
  now() + interval '2 days' + interval '1 hour',
  4
)
ON CONFLICT (id) DO NOTHING;

INSERT INTO availability_rules (tenant_id, staff_id, day_of_week, starts_local, ends_local)
SELECT
  '5d6b3551-0a3e-4b86-bdf0-e9df20a47148',
  '6936c444-c7d0-4a7d-b596-a9b72d2f4fc0',
  weekday,
  '09:00:00',
  '17:00:00'
FROM (VALUES (1), (2), (3), (4), (5)) AS weekdays(weekday)
WHERE NOT EXISTS (
  SELECT 1
  FROM availability_rules ar
  WHERE ar.tenant_id = '5d6b3551-0a3e-4b86-bdf0-e9df20a47148'
    AND ar.staff_id = '6936c444-c7d0-4a7d-b596-a9b72d2f4fc0'
    AND ar.day_of_week = weekdays.weekday
);

-- +goose Down
DELETE FROM availability_rules WHERE tenant_id = '5d6b3551-0a3e-4b86-bdf0-e9df20a47148';
DELETE FROM class_sessions WHERE id = '4bf74c12-44dd-45ca-86bb-b104f16f2435';
DELETE FROM class_templates WHERE id = 'd13fe5fd-727f-4d69-bfd8-47f1b92a2cf7';
DELETE FROM services WHERE id = 'd5d76a61-3d49-467c-8dd4-bf61ee754e39';
DELETE FROM staff WHERE id = '6936c444-c7d0-4a7d-b596-a9b72d2f4fc0';
DELETE FROM locations WHERE id = '659f1cc0-a850-46d6-b3b8-cb15d55d8daf';
DELETE FROM tenant_users WHERE tenant_id = '5d6b3551-0a3e-4b86-bdf0-e9df20a47148' AND user_id = '11111111-1111-1111-1111-111111111111';
DELETE FROM users WHERE id = '11111111-1111-1111-1111-111111111111';
DELETE FROM tenants WHERE id = '5d6b3551-0a3e-4b86-bdf0-e9df20a47148';
