-- ===========================================
-- MECANICAS DIESEL - Creación de Schemas
-- ===========================================
-- Ejecutar después de extensiones

-- Schemas propios de mecanicas-diesel
-- NOTA: Los schemas auth, core, inventory se heredan de erp-core

CREATE SCHEMA IF NOT EXISTS service_management;
COMMENT ON SCHEMA service_management IS 'Órdenes de servicio, diagnósticos, cotizaciones';

CREATE SCHEMA IF NOT EXISTS parts_management;
COMMENT ON SCHEMA parts_management IS 'Inventario de refacciones específico del taller';

CREATE SCHEMA IF NOT EXISTS vehicle_management;
COMMENT ON SCHEMA vehicle_management IS 'Vehículos diesel, flotas, motores';

-- Grants básicos
GRANT USAGE ON SCHEMA service_management TO mecanicas_user;
GRANT USAGE ON SCHEMA parts_management TO mecanicas_user;
GRANT USAGE ON SCHEMA vehicle_management TO mecanicas_user;

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA service_management TO mecanicas_user;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA parts_management TO mecanicas_user;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA vehicle_management TO mecanicas_user;

-- Default privileges para tablas futuras
ALTER DEFAULT PRIVILEGES IN SCHEMA service_management GRANT ALL ON TABLES TO mecanicas_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA parts_management GRANT ALL ON TABLES TO mecanicas_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA vehicle_management GRANT ALL ON TABLES TO mecanicas_user;
