using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
{
    /// <inheritdoc />
    public partial class GraduationAudits : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "GraduationAuditBatches",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    Name = table.Column<string>(type: "varchar(120)", maxLength: 120, nullable: false),
                    GraduationYear = table.Column<int>(type: "int", nullable: false),
                    EnrollmentYear = table.Column<int>(type: "int", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    Notes = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    CalculatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    PublishedAt = 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_GraduationAuditBatches", x => x.Id);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "GraduationAuditResults",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    GraduationAuditBatchId = table.Column<Guid>(type: "char(36)", nullable: false),
                    StudentId = table.Column<Guid>(type: "char(36)", nullable: false),
                    CurriculumPlanId = table.Column<Guid>(type: "char(36)", nullable: true),
                    StudentStatusSnapshot = table.Column<int>(type: "int", nullable: false),
                    RequiredCredits = table.Column<decimal>(type: "decimal(6,2)", precision: 6, scale: 2, nullable: false),
                    EarnedCredits = table.Column<decimal>(type: "decimal(6,2)", precision: 6, scale: 2, nullable: false),
                    RequiredCourseCount = table.Column<int>(type: "int", nullable: false),
                    PassedRequiredCourseCount = table.Column<int>(type: "int", nullable: false),
                    FailedCourseCount = table.Column<int>(type: "int", nullable: false),
                    MissingCourseNames = table.Column<string>(type: "varchar(2000)", maxLength: 2000, nullable: false),
                    CalculatedConclusion = table.Column<int>(type: "int", nullable: false),
                    Conclusion = table.Column<int>(type: "int", nullable: false),
                    IsOverridden = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    ReviewComment = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
                    ReviewedAt = 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_GraduationAuditResults", x => x.Id);
                    table.ForeignKey(
                        name: "FK_GraduationAuditResults_CurriculumPlans_CurriculumPlanId",
                        column: x => x.CurriculumPlanId,
                        principalTable: "CurriculumPlans",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_GraduationAuditResults_GraduationAuditBatches_GraduationAudi~",
                        column: x => x.GraduationAuditBatchId,
                        principalTable: "GraduationAuditBatches",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_GraduationAuditResults_Students_StudentId",
                        column: x => x.StudentId,
                        principalTable: "Students",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_GraduationAuditBatches_GraduationYear_EnrollmentYear",
                table: "GraduationAuditBatches",
                columns: new[] { "GraduationYear", "EnrollmentYear" });

            migrationBuilder.CreateIndex(
                name: "IX_GraduationAuditBatches_Status",
                table: "GraduationAuditBatches",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_GraduationAuditResults_Conclusion_IsOverridden",
                table: "GraduationAuditResults",
                columns: new[] { "Conclusion", "IsOverridden" });

            migrationBuilder.CreateIndex(
                name: "IX_GraduationAuditResults_CurriculumPlanId",
                table: "GraduationAuditResults",
                column: "CurriculumPlanId");

            migrationBuilder.CreateIndex(
                name: "IX_GraduationAuditResults_GraduationAuditBatchId_StudentId",
                table: "GraduationAuditResults",
                columns: new[] { "GraduationAuditBatchId", "StudentId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_GraduationAuditResults_StudentId",
                table: "GraduationAuditResults",
                column: "StudentId");
        }

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

            migrationBuilder.DropTable(
                name: "GraduationAuditBatches");
        }
    }
}
