using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BMA.EHR.Recurit.Exam.Service.Migrations
{
    /// <inheritdoc />
    public partial class UpdatetableCandidateaddbank : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "AnnounceDate",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "EndDate",
                table: "PeriodExams");

            migrationBuilder.RenameColumn(
                name: "StartDate",
                table: "PeriodExams",
                newName: "RegisterStartDate");

            migrationBuilder.AlterColumn<int>(
                name: "Round",
                table: "PeriodExams",
                type: "int",
                nullable: true,
                comment: "รอบการสอบ",
                oldClrType: typeof(int),
                oldType: "int",
                oldNullable: true,
                oldComment: "รอบการสอบ")
                .Annotation("Relational:ColumnOrder", 8)
                .OldAnnotation("Relational:ColumnOrder", 5);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "PeriodExams",
                type: "varchar(150)",
                maxLength: 150,
                nullable: false,
                comment: "ชื่อการสอบ",
                oldClrType: typeof(string),
                oldType: "varchar(150)",
                oldMaxLength: 150,
                oldComment: "ชื่อการสอบ")
                .Annotation("MySql:CharSet", "utf8mb4")
                .Annotation("Relational:ColumnOrder", 7)
                .OldAnnotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("Relational:ColumnOrder", 4);

            migrationBuilder.AddColumn<DateTime>(
                name: "AnnouncementEndDate",
                table: "PeriodExams",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
                comment: "วันสิ้นสุดประกาศ")
                .Annotation("Relational:ColumnOrder", 6);

            migrationBuilder.AddColumn<DateTime>(
                name: "AnnouncementStartDate",
                table: "PeriodExams",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
                comment: "วันเริ่มประกาศ")
                .Annotation("Relational:ColumnOrder", 5);

            migrationBuilder.AddColumn<bool>(
                name: "CheckDisability",
                table: "PeriodExams",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false,
                comment: "คนพิการ");

            migrationBuilder.AddColumn<bool>(
                name: "CheckDocument",
                table: "PeriodExams",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false,
                comment: "ตรวจสอบเอกสารหลังประกาศผลสอบ");

            migrationBuilder.AddColumn<string>(
                name: "Note",
                table: "PeriodExams",
                type: "longtext",
                nullable: true,
                comment: "หมายเหตุ")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<Guid>(
                name: "OrganizationCodeId",
                table: "PeriodExams",
                type: "char(36)",
                nullable: true,
                comment: "Id รหัสส่วนราชการ",
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<string>(
                name: "OrganizationCodeName",
                table: "PeriodExams",
                type: "longtext",
                nullable: true,
                comment: "ชื่อรหัสส่วนราชการ")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<Guid>(
                name: "OrganizationId",
                table: "PeriodExams",
                type: "char(36)",
                nullable: true,
                comment: "Id หน่วยงาน",
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<string>(
                name: "OrganizationName",
                table: "PeriodExams",
                type: "longtext",
                nullable: true,
                comment: "ชื่อหน่วยงาน")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<DateTime>(
                name: "PaymentEndDate",
                table: "PeriodExams",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
                comment: "วันสิ้นสุดชำระเงิน")
                .Annotation("Relational:ColumnOrder", 4);

            migrationBuilder.AddColumn<string>(
                name: "PaymentKrungThai",
                table: "PeriodExams",
                type: "longtext",
                nullable: true,
                comment: "ชำระเงินผ่านกรุงไทย")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<DateTime>(
                name: "PaymentStartDate",
                table: "PeriodExams",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
                comment: "วันเริ่มชำระเงิน")
                .Annotation("Relational:ColumnOrder", 3);

            migrationBuilder.AddColumn<DateTime>(
                name: "RegisterEndDate",
                table: "PeriodExams",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
                comment: "วันสิ้นสุดสมัครสอบ")
                .Annotation("Relational:ColumnOrder", 2);

            migrationBuilder.CreateTable(
                name: "BankExams",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "PrimaryKey", collation: "ascii_general_ci"),
                    CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "สร้างข้อมูลเมื่อ"),
                    CreatedUserId = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false, comment: "User Id ที่สร้างข้อมูล")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LastUpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "แก้ไขข้อมูลล่าสุดเมื่อ"),
                    LastUpdateUserId = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false, comment: "User Id ที่แก้ไขข้อมูลล่าสุด")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreatedFullName = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "ชื่อ User ที่สร้างข้อมูล")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LastUpdateFullName = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "ชื่อ User ที่แก้ไขข้อมูลล่าสุด")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PeriodExamId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    AccountNumber = table.Column<string>(type: "longtext", nullable: true, comment: "เลขบัญชี")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    BankName = table.Column<string>(type: "longtext", nullable: true, comment: "ธนาคาร")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    AccountName = table.Column<string>(type: "longtext", nullable: true, comment: "ชื่อบัญชี")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BankExams", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BankExams_PeriodExams_PeriodExamId",
                        column: x => x.PeriodExamId,
                        principalTable: "PeriodExams",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "PositionExams",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "PrimaryKey", collation: "ascii_general_ci"),
                    CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "สร้างข้อมูลเมื่อ"),
                    CreatedUserId = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false, comment: "User Id ที่สร้างข้อมูล")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LastUpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "แก้ไขข้อมูลล่าสุดเมื่อ"),
                    LastUpdateUserId = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false, comment: "User Id ที่แก้ไขข้อมูลล่าสุด")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreatedFullName = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "ชื่อ User ที่สร้างข้อมูล")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LastUpdateFullName = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "ชื่อ User ที่แก้ไขข้อมูลล่าสุด")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PeriodExamId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    PositionId = table.Column<Guid>(type: "char(36)", nullable: true, comment: "Id ตำแหน่ง", collation: "ascii_general_ci"),
                    PositionName = table.Column<string>(type: "longtext", nullable: true, comment: "ชื่อตำแหน่ง")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    TypeName = table.Column<string>(type: "longtext", nullable: true, comment: "ชื่อประเภทแบบฟอร์ม")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PositionExams", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PositionExams_PeriodExams_PeriodExamId",
                        column: x => x.PeriodExamId,
                        principalTable: "PeriodExams",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_BankExams_PeriodExamId",
                table: "BankExams",
                column: "PeriodExamId");

            migrationBuilder.CreateIndex(
                name: "IX_PositionExams_PeriodExamId",
                table: "PositionExams",
                column: "PeriodExamId");
        }

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

            migrationBuilder.DropTable(
                name: "PositionExams");

            migrationBuilder.DropColumn(
                name: "AnnouncementEndDate",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "AnnouncementStartDate",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "CheckDisability",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "CheckDocument",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "Note",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "OrganizationCodeId",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "OrganizationCodeName",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "OrganizationId",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "OrganizationName",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "PaymentEndDate",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "PaymentKrungThai",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "PaymentStartDate",
                table: "PeriodExams");

            migrationBuilder.DropColumn(
                name: "RegisterEndDate",
                table: "PeriodExams");

            migrationBuilder.RenameColumn(
                name: "RegisterStartDate",
                table: "PeriodExams",
                newName: "StartDate");

            migrationBuilder.AlterColumn<int>(
                name: "Round",
                table: "PeriodExams",
                type: "int",
                nullable: true,
                comment: "รอบการสอบ",
                oldClrType: typeof(int),
                oldType: "int",
                oldNullable: true,
                oldComment: "รอบการสอบ")
                .Annotation("Relational:ColumnOrder", 5)
                .OldAnnotation("Relational:ColumnOrder", 8);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "PeriodExams",
                type: "varchar(150)",
                maxLength: 150,
                nullable: false,
                comment: "ชื่อการสอบ",
                oldClrType: typeof(string),
                oldType: "varchar(150)",
                oldMaxLength: 150,
                oldComment: "ชื่อการสอบ")
                .Annotation("MySql:CharSet", "utf8mb4")
                .Annotation("Relational:ColumnOrder", 4)
                .OldAnnotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("Relational:ColumnOrder", 7);

            migrationBuilder.AddColumn<DateTime>(
                name: "AnnounceDate",
                table: "PeriodExams",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
                comment: "วันประกาศ")
                .Annotation("Relational:ColumnOrder", 3);

            migrationBuilder.AddColumn<DateTime>(
                name: "EndDate",
                table: "PeriodExams",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
                comment: "วันสิ้นสุด")
                .Annotation("Relational:ColumnOrder", 2);
        }
    }
}
