using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BMA.EHR.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class UpdatetablePlacementaddPlacementType : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "TypeExam",
                table: "Placements");

            migrationBuilder.AddColumn<Guid>(
                name: "PlacementTypeId",
                table: "Placements",
                type: "char(36)",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
                collation: "ascii_general_ci");

            migrationBuilder.CreateTable(
                name: "PlacementTypes",
                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"),
                    Name = table.Column<string>(type: "longtext", nullable: false, comment: "ชื่อประเภทบรรจุ")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "สถานะการใช้งาน")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PlacementTypes", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_Placements_PlacementTypeId",
                table: "Placements",
                column: "PlacementTypeId");

            migrationBuilder.AddForeignKey(
                name: "FK_Placements_PlacementTypes_PlacementTypeId",
                table: "Placements",
                column: "PlacementTypeId",
                principalTable: "PlacementTypes",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

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

            migrationBuilder.DropTable(
                name: "PlacementTypes");

            migrationBuilder.DropIndex(
                name: "IX_Placements_PlacementTypeId",
                table: "Placements");

            migrationBuilder.DropColumn(
                name: "PlacementTypeId",
                table: "Placements");

            migrationBuilder.AddColumn<string>(
                name: "TypeExam",
                table: "Placements",
                type: "longtext",
                nullable: false,
                comment: "ประเภทการสอบ")
                .Annotation("MySql:CharSet", "utf8mb4");
        }
    }
}
