using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
{
    /// <inheritdoc />
    public partial class DegreeAwards : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "DegreeAwardBatches",
                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),
                    DegreeName = table.Column<string>(type: "varchar(80)", maxLength: 80, nullable: false),
                    MinimumGradePoint = table.Column<decimal>(type: "decimal(3,2)", precision: 3, scale: 2, 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_DegreeAwardBatches", x => x.Id);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "DegreeAwardResults",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    DegreeAwardBatchId = table.Column<Guid>(type: "char(36)", nullable: false),
                    StudentId = table.Column<Guid>(type: "char(36)", nullable: false),
                    GraduationAuditResultId = table.Column<Guid>(type: "char(36)", nullable: false),
                    AverageGradePoint = table.Column<decimal>(type: "decimal(4,2)", precision: 4, scale: 2, nullable: false),
                    CalculatedConclusion = table.Column<int>(type: "int", nullable: false),
                    Conclusion = table.Column<int>(type: "int", nullable: false),
                    ExceptionReason = table.Column<string>(type: "varchar(500)", maxLength: 500, 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_DegreeAwardResults", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DegreeAwardResults_DegreeAwardBatches_DegreeAwardBatchId",
                        column: x => x.DegreeAwardBatchId,
                        principalTable: "DegreeAwardBatches",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_DegreeAwardResults_GraduationAuditResults_GraduationAuditRes~",
                        column: x => x.GraduationAuditResultId,
                        principalTable: "GraduationAuditResults",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_DegreeAwardResults_Students_StudentId",
                        column: x => x.StudentId,
                        principalTable: "Students",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_DegreeAwardBatches_GraduationYear_Status",
                table: "DegreeAwardBatches",
                columns: new[] { "GraduationYear", "Status" });

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

            migrationBuilder.CreateIndex(
                name: "IX_DegreeAwardResults_DegreeAwardBatchId_StudentId",
                table: "DegreeAwardResults",
                columns: new[] { "DegreeAwardBatchId", "StudentId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_DegreeAwardResults_GraduationAuditResultId",
                table: "DegreeAwardResults",
                column: "GraduationAuditResultId");

            migrationBuilder.CreateIndex(
                name: "IX_DegreeAwardResults_StudentId",
                table: "DegreeAwardResults",
                column: "StudentId");
        }

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

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