using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BMA.EHR.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddFieldtoCommandDeploymentTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.RenameColumn(
                name: "ExamRoundId",
                table: "Commands",
                newName: "PlacementId");

            migrationBuilder.AddColumn<string>(
                name: "CitizenId",
                table: "CommandDeployments",
                type: "varchar(13)",
                maxLength: 13,
                nullable: false,
                defaultValue: "",
                comment: "เลขประจำตัวประชาชน")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "FirstName",
                table: "CommandDeployments",
                type: "varchar(100)",
                maxLength: 100,
                nullable: false,
                defaultValue: "",
                comment: "ชื่อ")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "LastName",
                table: "CommandDeployments",
                type: "varchar(100)",
                maxLength: 100,
                nullable: false,
                defaultValue: "",
                comment: "นามสกุล")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "OrganizationName",
                table: "CommandDeployments",
                type: "longtext",
                nullable: false,
                comment: "ชื่อหน่วยงานของผู้รับสำเนาคำสั่ง")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Prefix",
                table: "CommandDeployments",
                type: "varchar(50)",
                maxLength: 50,
                nullable: false,
                defaultValue: "",
                comment: "คำนำหน้านาม")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<int>(
                name: "Sequence",
                table: "CommandDeployments",
                type: "int",
                nullable: false,
                defaultValue: 0,
                comment: "ลำดับ");

            migrationBuilder.CreateIndex(
                name: "IX_Commands_PlacementId",
                table: "Commands",
                column: "PlacementId");

            migrationBuilder.AddForeignKey(
                name: "FK_Commands_Placements_PlacementId",
                table: "Commands",
                column: "PlacementId",
                principalTable: "Placements",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Commands_Placements_PlacementId",
                table: "Commands");

            migrationBuilder.DropIndex(
                name: "IX_Commands_PlacementId",
                table: "Commands");

            migrationBuilder.DropColumn(
                name: "CitizenId",
                table: "CommandDeployments");

            migrationBuilder.DropColumn(
                name: "FirstName",
                table: "CommandDeployments");

            migrationBuilder.DropColumn(
                name: "LastName",
                table: "CommandDeployments");

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

            migrationBuilder.DropColumn(
                name: "Prefix",
                table: "CommandDeployments");

            migrationBuilder.DropColumn(
                name: "Sequence",
                table: "CommandDeployments");

            migrationBuilder.RenameColumn(
                name: "PlacementId",
                table: "Commands",
                newName: "ExamRoundId");
        }
    }
}
