-- DATA COMPLETA CONFIGURACION CARGOS LA LIBERTAD
-- 1. Limpiar tabla previa
TRUNCATE TABLE configuracion_cargos;

-- 2. INSERTAR TODOS LOS REGISTROS (Estructura Base del Usuario) --
-- PROVINCIAS (12)
INSERT INTO configuracion_cargos (tipo_eleccion, ubigeo) VALUES
('municipal_provincial','1301'),
('municipal_provincial','1302'),
('municipal_provincial','1303'),
('municipal_provincial','1304'),
('municipal_provincial','1305'),
('municipal_provincial','1306'),
('municipal_provincial','1307'),
('municipal_provincial','1308'),
('municipal_provincial','1309'),
('municipal_provincial','1310'),
('municipal_provincial','1311'),
('municipal_provincial','1312');

-- DISTRITOS (83)
INSERT INTO configuracion_cargos (tipo_eleccion, ubigeo) VALUES
('municipal_distrital','130101'),('municipal_distrital','130102'),('municipal_distrital','130103'),
('municipal_distrital','130104'),('municipal_distrital','130105'),('municipal_distrital','130106'),
('municipal_distrital','130107'),('municipal_distrital','130108'),('municipal_distrital','130109'),
('municipal_distrital','130110'),('municipal_distrital','130111'),
('municipal_distrital','130201'),('municipal_distrital','130202'),('municipal_distrital','130203'),
('municipal_distrital','130204'),('municipal_distrital','130205'),('municipal_distrital','130206'),
('municipal_distrital','130207'),('municipal_distrital','130208'),
('municipal_distrital','130301'),('municipal_distrital','130302'),('municipal_distrital','130303'),
('municipal_distrital','130304'),('municipal_distrital','130305'),('municipal_distrital','130306'),
('municipal_distrital','130401'),('municipal_distrital','130402'),('municipal_distrital','130403'),
('municipal_distrital','130501'),('municipal_distrital','130502'),('municipal_distrital','130503'),
('municipal_distrital','130504'),
('municipal_distrital','130601'),('municipal_distrital','130602'),('municipal_distrital','130603'),
('municipal_distrital','130604'),('municipal_distrital','130605'),('municipal_distrital','130606'),
('municipal_distrital','130607'),('municipal_distrital','130608'),('municipal_distrital','130609'),
('municipal_distrital','130610'),
('municipal_distrital','130701'),('municipal_distrital','130702'),('municipal_distrital','130703'),
('municipal_distrital','130704'),('municipal_distrital','130705'),
('municipal_distrital','130801'),('municipal_distrital','130802'),('municipal_distrital','130803'),
('municipal_distrital','130804'),('municipal_distrital','130805'),('municipal_distrital','130806'),
('municipal_distrital','130807'),('municipal_distrital','130808'),('municipal_distrital','130809'),
('municipal_distrital','130810'),('municipal_distrital','130811'),('municipal_distrital','130812'),
('municipal_distrital','130813'),
('municipal_distrital','130901'),('municipal_distrital','130902'),('municipal_distrital','130903'),
('municipal_distrital','130904'),('municipal_distrital','130905'),('municipal_distrital','130906'),
('municipal_distrital','130907'),('municipal_distrital','130908'),
('municipal_distrital','131001'),('municipal_distrital','131002'),('municipal_distrital','131003'),
('municipal_distrital','131004'),('municipal_distrital','131005'),('municipal_distrital','131006'),
('municipal_distrital','131007'),('municipal_distrital','131008'),
('municipal_distrital','131101'),('municipal_distrital','131102'),('municipal_distrital','131103'),
('municipal_distrital','131104'),('municipal_distrital','131105'),('municipal_distrital','131106'),
('municipal_distrital','131107'),
('municipal_distrital','131201'),('municipal_distrital','131202'),('municipal_distrital','131203');

-- REGION
INSERT INTO configuracion_cargos (tipo_eleccion, ubigeo) VALUES ('regional','13');


-- 3. APLICAR DATOS INVESTIGADOS (Overlay Inteligente) --

-- REGIONAL (21 Consejeros)
UPDATE configuracion_cargos SET num_consejeros = 21, fuente_normativa = 'Resolución N° 0001-2026-JNE' WHERE ubigeo = '13' AND tipo_eleccion = 'regional';

-- PROVINCIA TRUJILLO (15 Regidores)
UPDATE configuracion_cargos SET num_regidores = 15, fuente_normativa = 'Resolución N° 0913-2021-JNE' WHERE ubigeo = '1301';

-- PROVINCIAS 11 REGIDORES
UPDATE configuracion_cargos SET num_regidores = 11, fuente_normativa = 'Resolución N° 0913-2021-JNE' WHERE ubigeo IN ('1302','1304','1307','1309','1312') AND tipo_eleccion = 'municipal_provincial';

-- PROVINCIAS 9 REGIDORES
UPDATE configuracion_cargos SET num_regidores = 9, fuente_normativa = 'Resolución N° 0913-2021-JNE' WHERE ubigeo IN ('1306','1308','1310') AND tipo_eleccion = 'municipal_provincial';

-- PROVINCIAS 7 REGIDORES
UPDATE configuracion_cargos SET num_regidores = 7, fuente_normativa = 'Resolución N° 0913-2021-JNE' WHERE ubigeo IN ('1303','1305','1311') AND tipo_eleccion = 'municipal_provincial';

-- DISTRITOS GRANDES (11/9/7)
UPDATE configuracion_cargos SET num_regidores = 11 WHERE ubigeo IN ('130105','130102') AND tipo_eleccion = 'municipal_distrital';
UPDATE configuracion_cargos SET num_regidores = 9 WHERE ubigeo IN ('130104','130103','130111') AND tipo_eleccion = 'municipal_distrital';
UPDATE configuracion_cargos SET num_regidores = 7 WHERE ubigeo IN ('130106','130107') AND tipo_eleccion = 'municipal_distrital';

-- EL RESTO PERMANECE NULL (Se usará el fallback de 5 en backend) o podemos forzar 5.
-- Para que el Admin Panel se vea "completo", vamos a poner 5 en todos los distritales que sigan NULL.
UPDATE configuracion_cargos SET num_regidores = 5, fuente_normativa = 'Ley de Elecciones Municipales (Minimo)' 
WHERE tipo_eleccion = 'municipal_distrital' AND num_regidores IS NULL;
