CREATE TABLE IF NOT EXISTS `certificaciones` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `deportista_id` bigint unsigned NOT NULL,
  `tipo_certificacion` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `descripcion` longtext COLLATE utf8mb4_unicode_ci,
  `fecha_expedicion` date NOT NULL,
  `fecha_vencimiento` date DEFAULT NULL,
  `numero_certificado` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `archivo` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `estado` enum('activa','vencida','cancelada') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'activa',
  `registrado_por` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `numero_certificado` (`numero_certificado`),
  KEY `deportista_id` (`deportista_id`),
  KEY `tipo_certificacion` (`tipo_certificacion`),
  KEY `estado` (`estado`),
  KEY `registrado_por` (`registrado_por`),
  CONSTRAINT `certificaciones_ibfk_1` FOREIGN KEY (`deportista_id`) REFERENCES `deportistas` (`id`) ON DELETE CASCADE,
  CONSTRAINT `certificaciones_ibfk_2` FOREIGN KEY (`registrado_por`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
