-- ============================================================================
-- SEED DATA: Catálogos Vidrio Templado
-- FASE-8 ERP-Core - ERP Vidrio Templado
-- ============================================================================

-- Métodos de pago
INSERT INTO financial.payment_methods (tenant_id, name, code, payment_type, aplica_anticipo, porcentaje_anticipo)
SELECT current_setting('app.current_tenant_id', true)::UUID, name, code, payment_type::financial.payment_method_type, anticipo, porc
FROM (VALUES
    ('Anticipo 50%', 'anticipo', 'inbound', true, 50),
    ('Pago Producción', 'produccion', 'inbound', false, 0),
    ('Finiquito Instalación', 'finiquito', 'inbound', false, 0),
    ('Transferencia', 'transfer', 'inbound', false, 0),
    ('Efectivo', 'efectivo', 'inbound', false, 0)
) AS t(name, code, payment_type, anticipo, porc)
WHERE current_setting('app.current_tenant_id', true) IS NOT NULL
ON CONFLICT (tenant_id, code) DO NOTHING;

-- Skills vidrio
INSERT INTO hr.skill_types (tenant_id, name)
SELECT current_setting('app.current_tenant_id', true)::UUID, name
FROM (VALUES ('Proceso de Producción'), ('Instalación'), ('Maquinaria'), ('Calidad')) AS t(name)
WHERE current_setting('app.current_tenant_id', true) IS NOT NULL
ON CONFLICT DO NOTHING;

-- Ubicaciones de trabajo
INSERT INTO hr.work_locations (tenant_id, name, tipo_area, capacidad_m2, tiene_horno, temperatura_max)
SELECT current_setting('app.current_tenant_id', true)::UUID, name, tipo, cap, horno, temp
FROM (VALUES
    ('Área de Corte', 'corte', 200.0, false, NULL),
    ('Área de Pulido y Biselado', 'pulido', 100.0, false, NULL),
    ('Horno de Templado', 'templado', 150.0, true, 700),
    ('Almacén Materia Prima', 'almacen', 300.0, false, NULL),
    ('Almacén Producto Terminado', 'almacen', 200.0, false, NULL),
    ('Cuadrilla Instalación 1', 'instalacion', NULL, false, NULL),
    ('Cuadrilla Instalación 2', 'instalacion', NULL, false, NULL)
) AS t(name, tipo, cap, horno, temp)
WHERE current_setting('app.current_tenant_id', true) IS NOT NULL
ON CONFLICT DO NOTHING;

-- Estructuras de nómina
INSERT INTO hr.payslip_structures (tenant_id, name, code, tipo_pago)
SELECT current_setting('app.current_tenant_id', true)::UUID, name, code, tipo
FROM (VALUES
    ('Nómina Semanal', 'NOM-SEM', 'semanal'),
    ('Destajo Producción', 'DEST-PROD', 'destajo'),
    ('Destajo Instalación', 'DEST-INST', 'destajo')
) AS t(name, code, tipo)
WHERE current_setting('app.current_tenant_id', true) IS NOT NULL
ON CONFLICT (tenant_id, code) DO NOTHING;
