using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
{
    /// <inheritdoc />
    public partial class addtableDisciplineComplaint_Appeals : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "DisciplineComplaint_Appeals",
                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"),
                    Status = table.Column<string>(type: "longtext", nullable: false, comment: "สถานะอุทธรณ์/ร้องทุกข์")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Title = table.Column<string>(type: "text", nullable: true, comment: "เรื่องที่อุทธรณ์/ร้องทุกข์")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Description = table.Column<string>(type: "text", nullable: true, comment: "รายละเอียดของเรื่องอุทธรณ์/ร้องทุกข์")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Type = table.Column<string>(type: "longtext", nullable: false, comment: "ประเภทอุทธรณ์หรือร้องทุกข์")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Year = table.Column<int>(type: "int", nullable: true, comment: "ปีงบประมาณ"),
                    CaseType = table.Column<string>(type: "longtext", nullable: true, comment: "ประเภทคดี")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CaseNumber = table.Column<string>(type: "longtext", nullable: true, comment: "คดีเลขที่")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ProfileId = table.Column<Guid>(type: "char(36)", nullable: false, comment: "ProfileId", collation: "ascii_general_ci"),
                    CitizenId = table.Column<string>(type: "varchar(13)", maxLength: 13, nullable: true, comment: "รหัสบัตรประชาชน")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Fullname = table.Column<string>(type: "longtext", nullable: true, comment: "ชื่อ-นามสกุลผู้อุทธรณ์/ร้องทุกข์")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DisciplineComplaint_Appeals", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "DisciplineComplaint_Appeal_Docs",
                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"),
                    DisciplineComplaint_AppealId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DisciplineComplaint_Appeal_Docs", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DisciplineComplaint_Appeal_Docs_DisciplineComplaint_Appeals_~",
                        column: x => x.DisciplineComplaint_AppealId,
                        principalTable: "DisciplineComplaint_Appeals",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_DisciplineComplaint_Appeal_Docs_Documents_DocumentId",
                        column: x => x.DocumentId,
                        principalTable: "Documents",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "DisciplineComplaint_Appeal_Historys",
                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"),
                    Status = table.Column<string>(type: "longtext", nullable: false, comment: "สถานะอุทธรณ์/ร้องทุกข์")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DisciplineComplaint_AppealId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DisciplineComplaint_Appeal_Historys", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DisciplineComplaint_Appeal_Historys_DisciplineComplaint_Appe~",
                        column: x => x.DisciplineComplaint_AppealId,
                        principalTable: "DisciplineComplaint_Appeals",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_DisciplineComplaint_Appeal_Docs_DisciplineComplaint_AppealId",
                table: "DisciplineComplaint_Appeal_Docs",
                column: "DisciplineComplaint_AppealId");

            migrationBuilder.CreateIndex(
                name: "IX_DisciplineComplaint_Appeal_Docs_DocumentId",
                table: "DisciplineComplaint_Appeal_Docs",
                column: "DocumentId");

            migrationBuilder.CreateIndex(
                name: "IX_DisciplineComplaint_Appeal_Historys_DisciplineComplaint_Appe~",
                table: "DisciplineComplaint_Appeal_Historys",
                column: "DisciplineComplaint_AppealId");
        }

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

            migrationBuilder.DropTable(
                name: "DisciplineComplaint_Appeal_Historys");

            migrationBuilder.DropTable(
                name: "DisciplineComplaint_Appeals");
        }
    }
}
