using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
{
    /// <inheritdoc />
    public partial class ExamArrangementJobs : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "ExamArrangementJobs",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    Kind = table.Column<int>(type: "int", nullable: false),
                    PlanId = table.Column<Guid>(type: "char(36)", nullable: false),
                    ActivePlanId = table.Column<Guid>(type: "char(36)", nullable: true),
                    RequestedByUserId = table.Column<Guid>(type: "char(36)", nullable: true),
                    SessionIdsJson = table.Column<string>(type: "longtext", nullable: true),
                    AssignClassrooms = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    AssignInvigilators = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    TotalSessions = table.Column<int>(type: "int", nullable: false),
                    ProcessedSessions = table.Column<int>(type: "int", nullable: false),
                    CurrentStep = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true),
                    ResultMessage = table.Column<string>(type: "varchar(2000)", maxLength: 2000, nullable: true),
                    ErrorMessage = table.Column<string>(type: "varchar(2000)", maxLength: 2000, nullable: true),
                    StartedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    CompletedAt = 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_ExamArrangementJobs", x => x.Id);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_ExamArrangementJobs_Kind_Plan_CreatedAt",
                table: "ExamArrangementJobs",
                columns: new[] { "Kind", "PlanId", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_ExamArrangementJobs_RequestedByUserId",
                table: "ExamArrangementJobs",
                column: "RequestedByUserId");

            migrationBuilder.CreateIndex(
                name: "IX_ExamArrangementJobs_Status_CreatedAt",
                table: "ExamArrangementJobs",
                columns: new[] { "Status", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "UX_ExamArrangementJobs_Kind_ActivePlan",
                table: "ExamArrangementJobs",
                columns: new[] { "Kind", "ActivePlanId" },
                unique: true);
        }

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