-- 010_create_temporary_residences_table.sql
CREATE TABLE IF NOT EXISTS `temporary_residences` (
    `id`                BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    `nguoi_thue_id`     BIGINT UNSIGNED NOT NULL,
    `phong_id`          BIGINT UNSIGNED NOT NULL,
    `ngay_dang_ky`      DATE NOT NULL,
    `ngay_het_han`      DATE DEFAULT NULL,
    `so_to_khai`        VARCHAR(50) DEFAULT NULL,
    `trang_thai`        ENUM('dang_cu_tru','da_roi_di') NOT NULL DEFAULT 'dang_cu_tru',
    `ghi_chu`           TEXT DEFAULT NULL,
    `created_at`        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at`        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    KEY `temp_res_nguoi_thue_id_index` (`nguoi_thue_id`),
    KEY `temp_res_phong_id_index` (`phong_id`),
    CONSTRAINT `fk_temp_res_nguoi_thue`
        FOREIGN KEY (`nguoi_thue_id`) REFERENCES `tenants` (`id`) ON DELETE RESTRICT,
    CONSTRAINT `fk_temp_res_phong`
        FOREIGN KEY (`phong_id`) REFERENCES `rooms` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
