using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
{
    /// <inheritdoc />
    public partial class ClassroomReservations : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "ClassroomReservations",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    ApplicantUserId = table.Column<Guid>(type: "char(36)", nullable: false),
                    ApplicantName = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false),
                    ApplicantCollegeId = table.Column<Guid>(type: "char(36)", nullable: false),
                    AcademicTermId = table.Column<Guid>(type: "char(36)", nullable: false),
                    ClassroomId = table.Column<Guid>(type: "char(36)", nullable: false),
                    ReservationDate = table.Column<DateTime>(type: "date", nullable: false),
                    StartPeriod = table.Column<int>(type: "int", nullable: false),
                    PeriodCount = table.Column<int>(type: "int", nullable: false),
                    AttendeeCount = table.Column<int>(type: "int", nullable: false),
                    Purpose = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false),
                    ContactPhone = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: false),
                    Notes = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    Status = table.Column<int>(type: "int", nullable: false),
                    ReviewedByUserId = table.Column<Guid>(type: "char(36)", nullable: true),
                    ReviewedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    ReviewComment = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    CancelledAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ClassroomReservations", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ClassroomReservations_AcademicTerms_AcademicTermId",
                        column: x => x.AcademicTermId,
                        principalTable: "AcademicTerms",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_ClassroomReservations_AspNetUsers_ApplicantUserId",
                        column: x => x.ApplicantUserId,
                        principalTable: "AspNetUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_ClassroomReservations_AspNetUsers_ReviewedByUserId",
                        column: x => x.ReviewedByUserId,
                        principalTable: "AspNetUsers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_ClassroomReservations_Classrooms_ClassroomId",
                        column: x => x.ClassroomId,
                        principalTable: "Classrooms",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_ClassroomReservations_Colleges_ApplicantCollegeId",
                        column: x => x.ApplicantCollegeId,
                        principalTable: "Colleges",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_ClassroomReservations_AcademicTermId",
                table: "ClassroomReservations",
                column: "AcademicTermId");

            migrationBuilder.CreateIndex(
                name: "IX_ClassroomReservations_ApplicantCollegeId_Status_ReservationD~",
                table: "ClassroomReservations",
                columns: new[] { "ApplicantCollegeId", "Status", "ReservationDate" });

            migrationBuilder.CreateIndex(
                name: "IX_ClassroomReservations_ApplicantUserId_Status_CreatedAt",
                table: "ClassroomReservations",
                columns: new[] { "ApplicantUserId", "Status", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_ClassroomReservations_ClassroomId_ReservationDate_Status_Sta~",
                table: "ClassroomReservations",
                columns: new[] { "ClassroomId", "ReservationDate", "Status", "StartPeriod" });

            migrationBuilder.CreateIndex(
                name: "IX_ClassroomReservations_ReviewedByUserId",
                table: "ClassroomReservations",
                column: "ReviewedByUserId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ClassroomReservations");
        }
    }
}
