using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BMA.EHR.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddTableretire : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_InsigniaRequests_OrganizationOrganizations_OrganizationOrgan~",
                table: "InsigniaRequests");

            migrationBuilder.DropColumn(
                name: "PosNo",
                table: "Profiles");

            migrationBuilder.DropColumn(
                name: "Position",
                table: "Profiles");

            migrationBuilder.DropColumn(
                name: "PositionLevel",
                table: "Profiles");

            migrationBuilder.DropColumn(
                name: "PositionType",
                table: "Profiles");

            migrationBuilder.DropColumn(
                name: "Insignia",
                table: "ProfileInsignias");

            migrationBuilder.DropColumn(
                name: "Number",
                table: "PlacementProfiles");

            migrationBuilder.RenameColumn(
                name: "OrganizationOrganizationId",
                table: "InsigniaRequests",
                newName: "OrganizationId");

            migrationBuilder.RenameIndex(
                name: "IX_InsigniaRequests_OrganizationOrganizationId",
                table: "InsigniaRequests",
                newName: "IX_InsigniaRequests_OrganizationId");

            migrationBuilder.AlterColumn<Guid>(
                name: "PositionLevelId",
                table: "ProfileSalaries",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true,
                oldComment: "Id ระดับ")
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AddColumn<int>(
                name: "Order",
                table: "ProfileSalaries",
                type: "int",
                nullable: true,
                comment: "ลำดับ");

            migrationBuilder.AlterColumn<Guid>(
                name: "PrefixId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true,
                oldComment: "Id คำนำหน้า")
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "PositionTypeId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true,
                oldComment: "Id ประเภทตำแหน่ง")
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "PositionLevelId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true,
                oldComment: " Id ระดับ")
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "PositionId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true,
                oldComment: "Id ตำแหน่ง")
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "PosNoId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true,
                oldComment: "Id เลขที่ตำแหน่ง")
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "GenderId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true,
                oldComment: "Id เพศ")
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "Profiles",
                type: "char(36)",
                nullable: false,
                comment: "PrimaryKey",
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)")
                .Annotation("Relational:ColumnOrder", 0)
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.CreateTable(
                name: "Retirements",
                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"),
                    Round = table.Column<int>(type: "int", nullable: false, comment: "ครั้งที่"),
                    Type = table.Column<string>(type: "longtext", nullable: false, comment: "ประเภท")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Retirements", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "RetirementProfiles",
                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"),
                    Order = table.Column<int>(type: "int", nullable: false, comment: "ลำดับที่"),
                    Reason = table.Column<string>(type: "longtext", nullable: false, comment: "เหตุผล")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Remove = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "ลบออกจากเกษียญ"),
                    RetirementId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ProfileId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RetirementProfiles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_RetirementProfiles_Profiles_ProfileId",
                        column: x => x.ProfileId,
                        principalTable: "Profiles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_RetirementProfiles_Retirements_RetirementId",
                        column: x => x.RetirementId,
                        principalTable: "Retirements",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_ProfileSalaries_PositionLevelId",
                table: "ProfileSalaries",
                column: "PositionLevelId");

            migrationBuilder.CreateIndex(
                name: "IX_Profiles_GenderId",
                table: "Profiles",
                column: "GenderId");

            migrationBuilder.CreateIndex(
                name: "IX_Profiles_PositionId",
                table: "Profiles",
                column: "PositionId");

            migrationBuilder.CreateIndex(
                name: "IX_Profiles_PositionLevelId",
                table: "Profiles",
                column: "PositionLevelId");

            migrationBuilder.CreateIndex(
                name: "IX_Profiles_PositionTypeId",
                table: "Profiles",
                column: "PositionTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_Profiles_PosNoId",
                table: "Profiles",
                column: "PosNoId");

            migrationBuilder.CreateIndex(
                name: "IX_Profiles_PrefixId",
                table: "Profiles",
                column: "PrefixId");

            migrationBuilder.CreateIndex(
                name: "IX_ProfileInsignias_InsigniaId",
                table: "ProfileInsignias",
                column: "InsigniaId");

            migrationBuilder.CreateIndex(
                name: "IX_RetirementProfiles_ProfileId",
                table: "RetirementProfiles",
                column: "ProfileId");

            migrationBuilder.CreateIndex(
                name: "IX_RetirementProfiles_RetirementId",
                table: "RetirementProfiles",
                column: "RetirementId");

            migrationBuilder.AddForeignKey(
                name: "FK_InsigniaRequests_Organizations_OrganizationId",
                table: "InsigniaRequests",
                column: "OrganizationId",
                principalTable: "Organizations",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_ProfileInsignias_Insignias_InsigniaId",
                table: "ProfileInsignias",
                column: "InsigniaId",
                principalTable: "Insignias",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Profiles_Genders_GenderId",
                table: "Profiles",
                column: "GenderId",
                principalTable: "Genders",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Profiles_PositionLevels_PositionLevelId",
                table: "Profiles",
                column: "PositionLevelId",
                principalTable: "PositionLevels",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Profiles_PositionNumbers_PosNoId",
                table: "Profiles",
                column: "PosNoId",
                principalTable: "PositionNumbers",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Profiles_PositionPaths_PositionId",
                table: "Profiles",
                column: "PositionId",
                principalTable: "PositionPaths",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Profiles_PositionTypes_PositionTypeId",
                table: "Profiles",
                column: "PositionTypeId",
                principalTable: "PositionTypes",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Profiles_Prefixes_PrefixId",
                table: "Profiles",
                column: "PrefixId",
                principalTable: "Prefixes",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_ProfileSalaries_PositionLevels_PositionLevelId",
                table: "ProfileSalaries",
                column: "PositionLevelId",
                principalTable: "PositionLevels",
                principalColumn: "Id");
        }

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

            migrationBuilder.DropForeignKey(
                name: "FK_ProfileInsignias_Insignias_InsigniaId",
                table: "ProfileInsignias");

            migrationBuilder.DropForeignKey(
                name: "FK_Profiles_Genders_GenderId",
                table: "Profiles");

            migrationBuilder.DropForeignKey(
                name: "FK_Profiles_PositionLevels_PositionLevelId",
                table: "Profiles");

            migrationBuilder.DropForeignKey(
                name: "FK_Profiles_PositionNumbers_PosNoId",
                table: "Profiles");

            migrationBuilder.DropForeignKey(
                name: "FK_Profiles_PositionPaths_PositionId",
                table: "Profiles");

            migrationBuilder.DropForeignKey(
                name: "FK_Profiles_PositionTypes_PositionTypeId",
                table: "Profiles");

            migrationBuilder.DropForeignKey(
                name: "FK_Profiles_Prefixes_PrefixId",
                table: "Profiles");

            migrationBuilder.DropForeignKey(
                name: "FK_ProfileSalaries_PositionLevels_PositionLevelId",
                table: "ProfileSalaries");

            migrationBuilder.DropTable(
                name: "RetirementProfiles");

            migrationBuilder.DropTable(
                name: "Retirements");

            migrationBuilder.DropIndex(
                name: "IX_ProfileSalaries_PositionLevelId",
                table: "ProfileSalaries");

            migrationBuilder.DropIndex(
                name: "IX_Profiles_GenderId",
                table: "Profiles");

            migrationBuilder.DropIndex(
                name: "IX_Profiles_PositionId",
                table: "Profiles");

            migrationBuilder.DropIndex(
                name: "IX_Profiles_PositionLevelId",
                table: "Profiles");

            migrationBuilder.DropIndex(
                name: "IX_Profiles_PositionTypeId",
                table: "Profiles");

            migrationBuilder.DropIndex(
                name: "IX_Profiles_PosNoId",
                table: "Profiles");

            migrationBuilder.DropIndex(
                name: "IX_Profiles_PrefixId",
                table: "Profiles");

            migrationBuilder.DropIndex(
                name: "IX_ProfileInsignias_InsigniaId",
                table: "ProfileInsignias");

            migrationBuilder.DropColumn(
                name: "Order",
                table: "ProfileSalaries");

            migrationBuilder.RenameColumn(
                name: "OrganizationId",
                table: "InsigniaRequests",
                newName: "OrganizationOrganizationId");

            migrationBuilder.RenameIndex(
                name: "IX_InsigniaRequests_OrganizationId",
                table: "InsigniaRequests",
                newName: "IX_InsigniaRequests_OrganizationOrganizationId");

            migrationBuilder.AlterColumn<Guid>(
                name: "PositionLevelId",
                table: "ProfileSalaries",
                type: "char(36)",
                nullable: true,
                comment: "Id ระดับ",
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true)
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "PrefixId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                comment: "Id คำนำหน้า",
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true)
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "PositionTypeId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                comment: "Id ประเภทตำแหน่ง",
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true)
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "PositionLevelId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                comment: " Id ระดับ",
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true)
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "PositionId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                comment: "Id ตำแหน่ง",
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true)
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "PosNoId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                comment: "Id เลขที่ตำแหน่ง",
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true)
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "GenderId",
                table: "Profiles",
                type: "char(36)",
                nullable: true,
                comment: "Id เพศ",
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true)
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "Profiles",
                type: "char(36)",
                nullable: false,
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldComment: "PrimaryKey")
                .OldAnnotation("Relational:Collation", "ascii_general_ci")
                .OldAnnotation("Relational:ColumnOrder", 0);

            migrationBuilder.AddColumn<string>(
                name: "PosNo",
                table: "Profiles",
                type: "longtext",
                nullable: true,
                comment: "เลขที่ตำแหน่ง")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Position",
                table: "Profiles",
                type: "longtext",
                nullable: true,
                comment: "ตำแหน่ง")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "PositionLevel",
                table: "Profiles",
                type: "longtext",
                nullable: true,
                comment: "ระดับ")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "PositionType",
                table: "Profiles",
                type: "longtext",
                nullable: true,
                comment: "ประเภทตำแหน่ง")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Insignia",
                table: "ProfileInsignias",
                type: "longtext",
                nullable: true,
                comment: "ชื่อเครื่องราชฯ")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<int>(
                name: "Number",
                table: "PlacementProfiles",
                type: "int",
                nullable: true,
                comment: "ลำดับที่สอบได้");

            migrationBuilder.AddForeignKey(
                name: "FK_InsigniaRequests_OrganizationOrganizations_OrganizationOrgan~",
                table: "InsigniaRequests",
                column: "OrganizationOrganizationId",
                principalTable: "OrganizationOrganizations",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
