-- Creación de base de datos para hotel alura
CREATE DATABASE IF NOT EXISTS `hotel_alura` 
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

USE `hotel_alura`;

DELETE FROM `hotel_alura`.`huesped`;
DROP TABLE IF EXISTS `hotel_alura`.`reserva`;
DROP TABLE IF EXISTS `hotel_alura`.`huesped`;

CREATE TABLE IF NOT EXISTS `huesped` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `usuario` varchar(20) NOT NULL UNIQUE,
  `nombre` varchar(20) NOT NULL,
  `apellido` varchar(20) NOT NULL,
  `fecha_nacimiento` date DEFAULT '1000-01-01',
  `nacionalidad` varchar(20) DEFAULT 'chilena',
  `telefono` varchar(20) NOT NULL,
  `password` varchar(60) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

CREATE TABLE IF NOT EXISTS `reserva` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `fecha_entrada` date NOT NULL,
  `fecha_salida` date NOT NULL,
  `valor` double NOT NULL,
  `forma_pago` varchar(20) NOT NULL,
  `id_huesped` int(11) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `id_huesped_idx` (`id_huesped`),
  CONSTRAINT `id_huesped` FOREIGN KEY (`id_huesped`) REFERENCES `huesped` (`id`)
  ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

