-- HU-ROOMS: Datos iniciales para demo/desarrollo

-- ============================================
-- Tipos de recurso
-- ============================================
INSERT INTO public.resource_types (slug, name, icon, description) VALUES
  ('meeting_room', 'Sala de Reuniones', 'door-open', 'Salas para reuniones y videoconferencias'),
  ('parking_spot', 'Estacionamiento', 'car', 'Espacios de estacionamiento'),
  ('desk', 'Escritorio Flex', 'laptop', 'Escritorios para trabajo individual'),
  ('phone_booth', 'Cabina Telefónica', 'phone', 'Cabinas privadas para llamadas'),
  ('locker', 'Locker', 'lock', 'Casilleros personales')
ON CONFLICT (slug) DO NOTHING;

-- ============================================
-- Oficinas
-- ============================================
INSERT INTO public.offices (id, name, address, timezone) VALUES
  ('a0000000-0000-0000-0000-000000000001', 'Oficina Santiago Centro', 'Av. Providencia 1234, Santiago', 'America/Santiago'),
  ('a0000000-0000-0000-0000-000000000002', 'Oficina Las Condes', 'Av. Apoquindo 5678, Las Condes', 'America/Santiago')
ON CONFLICT (id) DO NOTHING;

-- ============================================
-- Recursos: Salas de reuniones
-- ============================================
INSERT INTO public.resources (office_id, resource_type_id, name, description, capacity, floor, attributes)
SELECT 
  'a0000000-0000-0000-0000-000000000001',
  rt.id,
  r.name,
  r.description,
  r.capacity,
  r.floor,
  r.attributes::jsonb
FROM public.resource_types rt,
(VALUES
  ('Sala Atacama', 'Sala grande con vista panorámica', 12, 'Piso 5', '{"has_tv": true, "has_whiteboard": true, "has_video_conference": true}'),
  ('Sala Elqui', 'Sala mediana ideal para equipos', 8, 'Piso 5', '{"has_tv": true, "has_whiteboard": true, "has_video_conference": true}'),
  ('Sala Maipo', 'Sala pequeña para reuniones rápidas', 4, 'Piso 4', '{"has_tv": true, "has_whiteboard": false, "has_video_conference": false}'),
  ('Sala Aconcagua', 'Sala ejecutiva', 6, 'Piso 6', '{"has_tv": true, "has_whiteboard": true, "has_video_conference": true}')
) AS r(name, description, capacity, floor, attributes)
WHERE rt.slug = 'meeting_room'
ON CONFLICT DO NOTHING;

-- Salas en Las Condes
INSERT INTO public.resources (office_id, resource_type_id, name, description, capacity, floor, attributes)
SELECT 
  'a0000000-0000-0000-0000-000000000002',
  rt.id,
  r.name,
  r.description,
  r.capacity,
  r.floor,
  r.attributes::jsonb
FROM public.resource_types rt,
(VALUES
  ('Sala Patagonia', 'Sala amplia con equipamiento completo', 10, 'Piso 3', '{"has_tv": true, "has_whiteboard": true, "has_video_conference": true}'),
  ('Sala Torres del Paine', 'Sala mediana con vista', 6, 'Piso 3', '{"has_tv": true, "has_whiteboard": true, "has_video_conference": false}')
) AS r(name, description, capacity, floor, attributes)
WHERE rt.slug = 'meeting_room'
ON CONFLICT DO NOTHING;

-- ============================================
-- Recursos: Estacionamientos
-- ============================================
INSERT INTO public.resources (office_id, resource_type_id, name, description, capacity, floor, attributes)
SELECT 
  'a0000000-0000-0000-0000-000000000001',
  rt.id,
  r.name,
  r.description,
  1,
  r.floor,
  r.attributes::jsonb
FROM public.resource_types rt,
(VALUES
  ('E-01', 'Estacionamiento cubierto', 'Subterráneo 1', '{"covered": true, "electric_charger": false}'),
  ('E-02', 'Estacionamiento cubierto', 'Subterráneo 1', '{"covered": true, "electric_charger": false}'),
  ('E-03', 'Estacionamiento con cargador eléctrico', 'Subterráneo 1', '{"covered": true, "electric_charger": true}'),
  ('E-04', 'Estacionamiento cubierto', 'Subterráneo 1', '{"covered": true, "electric_charger": false}'),
  ('E-05', 'Estacionamiento cubierto', 'Subterráneo 1', '{"covered": true, "electric_charger": false}')
) AS r(name, description, floor, attributes)
WHERE rt.slug = 'parking_spot'
ON CONFLICT DO NOTHING;

-- ============================================
-- Recursos: Escritorios flex
-- ============================================
INSERT INTO public.resources (office_id, resource_type_id, name, description, capacity, floor, attributes)
SELECT 
  'a0000000-0000-0000-0000-000000000001',
  rt.id,
  r.name,
  r.description,
  1,
  r.floor,
  r.attributes::jsonb
FROM public.resource_types rt,
(VALUES
  ('Desk A-01', 'Escritorio zona tranquila', 'Piso 4', '{"has_monitor": true, "near_window": true}'),
  ('Desk A-02', 'Escritorio zona tranquila', 'Piso 4', '{"has_monitor": true, "near_window": false}'),
  ('Desk A-03', 'Escritorio zona colaborativa', 'Piso 4', '{"has_monitor": true, "near_window": false}'),
  ('Desk B-01', 'Escritorio zona tranquila', 'Piso 5', '{"has_monitor": true, "near_window": true}'),
  ('Desk B-02', 'Escritorio zona colaborativa', 'Piso 5', '{"has_monitor": false, "near_window": false}')
) AS r(name, description, floor, attributes)
WHERE rt.slug = 'desk'
ON CONFLICT DO NOTHING;

-- ============================================
-- Recursos: Cabinas telefónicas
-- ============================================
INSERT INTO public.resources (office_id, resource_type_id, name, description, capacity, floor, attributes)
SELECT 
  'a0000000-0000-0000-0000-000000000001',
  rt.id,
  r.name,
  r.description,
  1,
  r.floor,
  '{}'::jsonb
FROM public.resource_types rt,
(VALUES
  ('Phone Booth 1', 'Cabina insonorizada', 'Piso 4'),
  ('Phone Booth 2', 'Cabina insonorizada', 'Piso 5')
) AS r(name, description, floor)
WHERE rt.slug = 'phone_booth'
ON CONFLICT DO NOTHING;

-- ============================================
-- Políticas de recursos
-- ============================================
INSERT INTO public.resource_policies (resource_type_id, min_duration_minutes, max_duration_minutes, advance_booking_days, cancellation_window_minutes, no_show_threshold_minutes)
SELECT 
  rt.id,
  p.min_duration,
  p.max_duration,
  p.advance_days,
  p.cancel_window,
  p.no_show_threshold
FROM public.resource_types rt,
(VALUES
  ('meeting_room', 30, 240, 14, 30, 10),
  ('parking_spot', 60, 600, 7, 60, 15),
  ('desk', 60, 480, 7, 30, 15),
  ('phone_booth', 15, 60, 1, 15, 5),
  ('locker', 1440, 43200, 30, 1440, 60)
) AS p(slug, min_duration, max_duration, advance_days, cancel_window, no_show_threshold)
WHERE rt.slug = p.slug
ON CONFLICT DO NOTHING;

-- ============================================
-- Usuario admin demo
-- ============================================
INSERT INTO public.users (email, display_name, role) VALUES
  ('admin@humand.co', 'Admin Demo', 'admin'),
  ('usuario@humand.co', 'Usuario Demo', 'user')
ON CONFLICT (email) DO NOTHING;
