CREATE TABLE IF NOT EXISTS `ie_ambiente` (
  `id_ambiente` int unsigned NOT NULL AUTO_INCREMENT,
  `id_institucion` smallint unsigned NOT NULL DEFAULT 1,
  `codigo` varchar(10) NOT NULL,
  `descripcion` varchar(180) NOT NULL,
  `tipo_ambiente` varchar(80) NOT NULL DEFAULT 'AULA DE CLASES',
  `ubicacion` varchar(180) DEFAULT NULL,
  `capacidad_estudiantes` smallint unsigned DEFAULT NULL,
  `area_m2` decimal(8,2) DEFAULT NULL,
  `estado` varchar(30) NOT NULL DEFAULT 'BUENO',
  `carpetas_bueno` smallint unsigned DEFAULT NULL,
  `carpetas_regular` smallint unsigned DEFAULT NULL,
  `carpetas_malo` smallint unsigned DEFAULT NULL,
  `sillas_bueno` smallint unsigned DEFAULT NULL,
  `sillas_regular` smallint unsigned DEFAULT NULL,
  `sillas_malo` smallint unsigned DEFAULT NULL,
  `mesas_bueno` smallint unsigned DEFAULT NULL,
  `mesas_regular` smallint unsigned DEFAULT NULL,
  `mesas_malo` smallint unsigned DEFAULT NULL,
  `armarios_bueno` smallint unsigned DEFAULT NULL,
  `armarios_regular` smallint unsigned DEFAULT NULL,
  `armarios_malo` smallint unsigned DEFAULT NULL,
  `observacion` text,
  `estado_registro` tinyint(1) NOT NULL DEFAULT 1,
  `creado_en` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `actualizado_en` datetime DEFAULT NULL,
  PRIMARY KEY (`id_ambiente`),
  KEY `idx_ie_ambiente_codigo` (`codigo`),
  KEY `idx_ie_ambiente_tipo` (`tipo_ambiente`),
  KEY `idx_ie_ambiente_estado` (`estado`, `estado_registro`),
  CONSTRAINT `fk_ie_ambiente_institucion`
    FOREIGN KEY (`id_institucion`) REFERENCES `institucion_educativa` (`id_institucion`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `ie_ambiente`
(`id_ambiente`, `id_institucion`, `codigo`, `descripcion`, `tipo_ambiente`, `ubicacion`, `capacidad_estudiantes`, `area_m2`, `estado`, `estado_registro`, `creado_en`, `actualizado_en`)
VALUES
(1, 1, '01', 'Aula Generica de la IE1', 'AULA DE CLASES', NULL, NULL, NULL, 'BUENO', 1, NOW(), NOW()),
(2, 1, '02', 'Aula Generica de la IE2', 'AULA DE CLASES', NULL, NULL, NULL, 'BUENO', 1, NOW(), NOW()),
(3, 1, '03', 'Aula Generica de la IE3', 'AULA DE CLASES', NULL, NULL, NULL, 'BUENO', 1, NOW(), NOW()),
(4, 1, '04', 'Aula Generica de la IE4', 'AULA DE CLASES', NULL, NULL, NULL, 'BUENO', 1, NOW(), NOW()),
(5, 1, '05', 'Aula Generica de la IE5', 'AULA DE CLASES', NULL, NULL, NULL, 'BUENO', 1, NOW(), NOW()),
(6, 1, '06', 'Aula Generica de la IE6', 'AULA DE CLASES', NULL, NULL, NULL, 'BUENO', 1, NOW(), NOW()),
(7, 1, '07', 'AULA 1', 'AULA DE CLASES', '1 - 1 PISO', 20, 48.00, 'REGULAR', 1, NOW(), NOW()),
(8, 1, '08', 'AULA 2', 'AULA DE CLASES', '1 - 1 PISO', 20, 48.00, 'REGULAR', 1, NOW(), NOW()),
(9, 1, '09', 'AULA 3', 'AULA DE CLASES', '1 - 1 PISO', 20, 48.00, 'REGULAR', 1, NOW(), NOW()),
(10, 1, '10', 'AULA 4', 'AULA DE CLASES', '1 - 1 PISO', 20, 48.00, 'BUENO', 1, NOW(), NOW()),
(11, 1, '11', 'AULA 5', 'AULA DE CLASES', '1 - 1 PISO', 20, 48.00, 'REGULAR', 1, NOW(), NOW()),
(12, 1, '12', 'AULA 6', 'AULA DE CLASES', '1 - 1 PISO', 20, 48.00, 'REGULAR', 1, NOW(), NOW()),
(13, 1, '13', 'AULA 7', 'AULA DE CLASES', '1 - 1 PISO', 20, 48.00, 'REGULAR', 1, NOW(), NOW())
ON DUPLICATE KEY UPDATE
  `codigo` = VALUES(`codigo`),
  `descripcion` = VALUES(`descripcion`),
  `tipo_ambiente` = VALUES(`tipo_ambiente`),
  `ubicacion` = VALUES(`ubicacion`),
  `capacidad_estudiantes` = VALUES(`capacidad_estudiantes`),
  `area_m2` = VALUES(`area_m2`),
  `estado` = VALUES(`estado`),
  `estado_registro` = 1,
  `actualizado_en` = NOW();
