using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BMA.EHR.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class updatetableRetirementResignsadddebt : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "CancelReason",
                table: "RetirementResigns",
                type: "longtext",
                nullable: true,
                comment: "เหตุผลยกเลิก")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<bool>(
                name: "IsNoDebt",
                table: "RetirementResigns",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false,
                comment: "สถานะไม่เป็นหนี้สหกรณ์");

            migrationBuilder.CreateTable(
                name: "RetirementResignDebtDocs",
                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"),
                    DocumentId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    RetirementResignId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RetirementResignDebtDocs", x => x.Id);
                    table.ForeignKey(
                        name: "FK_RetirementResignDebtDocs_Documents_DocumentId",
                        column: x => x.DocumentId,
                        principalTable: "Documents",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_RetirementResignDebtDocs_RetirementResigns_RetirementResignId",
                        column: x => x.RetirementResignId,
                        principalTable: "RetirementResigns",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_RetirementResignDebtDocs_DocumentId",
                table: "RetirementResignDebtDocs",
                column: "DocumentId");

            migrationBuilder.CreateIndex(
                name: "IX_RetirementResignDebtDocs_RetirementResignId",
                table: "RetirementResignDebtDocs",
                column: "RetirementResignId");
        }

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

            migrationBuilder.DropColumn(
                name: "CancelReason",
                table: "RetirementResigns");

            migrationBuilder.DropColumn(
                name: "IsNoDebt",
                table: "RetirementResigns");
        }
    }
}
