using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
{
    /// <inheritdoc />
    public partial class CourseSelectionGradeLimits : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "MaxCourseCount",
                table: "CourseSelectionRounds",
                type: "int",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "CourseSelectionRoundGrades",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    CourseSelectionRoundId = table.Column<Guid>(type: "char(36)", nullable: false),
                    Grade = table.Column<int>(type: "int", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CourseSelectionRoundGrades", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CourseSelectionRoundGrades_CourseSelectionRounds_CourseSelec~",
                        column: x => x.CourseSelectionRoundId,
                        principalTable: "CourseSelectionRounds",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_CourseSelectionRoundGrades_CourseSelectionRoundId_Grade",
                table: "CourseSelectionRoundGrades",
                columns: new[] { "CourseSelectionRoundId", "Grade" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_CourseSelectionRoundGrades_Grade",
                table: "CourseSelectionRoundGrades",
                column: "Grade");
        }

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

            migrationBuilder.DropColumn(
                name: "MaxCourseCount",
                table: "CourseSelectionRounds");
        }
    }
}
