-- HU-ROOMS: Ejecutar en Supabase → SQL Editor (proyecto remoto)
-- Corrige 42501 "new row violates row-level security policy" al crear/editar recursos
-- y permite gestionar tipos de recurso desde el admin autenticado.
--
-- Causa típica: solo existía política SELECT; INSERT requiere política explícita para rol `authenticated`.

-- ---------- resources ----------
DROP POLICY IF EXISTS "resources_insert_authenticated" ON public.resources;
CREATE POLICY "resources_insert_authenticated" ON public.resources
  FOR INSERT TO authenticated
  WITH CHECK (true);

DROP POLICY IF EXISTS "resources_update_authenticated" ON public.resources;
CREATE POLICY "resources_update_authenticated" ON public.resources
  FOR UPDATE TO authenticated
  USING (true)
  WITH CHECK (true);

DROP POLICY IF EXISTS "resources_delete_authenticated" ON public.resources;
CREATE POLICY "resources_delete_authenticated" ON public.resources
  FOR DELETE TO authenticated
  USING (true);

-- ---------- resource_types (CRUD admin) ----------
DROP POLICY IF EXISTS "resource_types_insert_authenticated" ON public.resource_types;
CREATE POLICY "resource_types_insert_authenticated" ON public.resource_types
  FOR INSERT TO authenticated
  WITH CHECK (true);

DROP POLICY IF EXISTS "resource_types_update_authenticated" ON public.resource_types;
CREATE POLICY "resource_types_update_authenticated" ON public.resource_types
  FOR UPDATE TO authenticated
  USING (true)
  WITH CHECK (true);

DROP POLICY IF EXISTS "resource_types_delete_authenticated" ON public.resource_types;
CREATE POLICY "resource_types_delete_authenticated" ON public.resource_types
  FOR DELETE TO authenticated
  USING (true);
