using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BMA.EHR.Recurit.Exam.Service.Migrations
{
    /// <inheritdoc />
    public partial class createtableCandidate : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "PeriodExams",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "PrimaryKey", collation: "ascii_general_ci"),
                    Name = table.Column<string>(type: "varchar(150)", maxLength: 150, nullable: false, comment: "ชื่อการสอบ")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    StartDate = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "วันเริ่มสมัครสอบ"),
                    EndDate = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "วันสิ้นสุด"),
                    Detail = table.Column<string>(type: "longtext", nullable: false, comment: "รายละเอียดสมัครสอบ")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "สถานะการใช้งาน"),
                    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")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PeriodExams", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Candidates",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "PrimaryKey", collation: "ascii_general_ci"),
                    FirstName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "ชื่อจริง")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LastName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "นามสกุล")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Nationality = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false, comment: "สัญชาติ")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    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"),
                    PeriodExamId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    UserId = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false, comment: "User Id ผู้สมัคร")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PrefixId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    DateOfBirth = table.Column<DateTime>(type: "datetime(6)", maxLength: 40, nullable: true, comment: "วันเกิด"),
                    RelationshipId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    Email = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "อีเมล")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CitizenId = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false, comment: "เลขประจำตัวประชาชน")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CitizenDistrictId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    CitizenProvinceId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    CitizenDate = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "วันที่ออกบัตร"),
                    Telephone = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false, comment: "โทรศัพท์")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    MobilePhone = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false, comment: "โทรศัพท์มือถือ")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Knowledge = table.Column<string>(type: "longtext", nullable: false, comment: "ความสามารถพิเศษ")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    RegistAddress = table.Column<string>(type: "longtext", nullable: false, comment: "ที่อยู่ตามทะเบียนบ้าน")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    RegistProvinceId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    RegistDistrictId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    RegistSubDistrictId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    RegistZipCode = table.Column<string>(type: "varchar(10)", maxLength: 10, nullable: false, comment: "รหัสไปรษณีย์ที่อยู่ตามทะเบียนบ้าน")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    RegistSame = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "ที่อยู่ปัจจุบันเหมือนที่อยู่ตามทะเบียนบ้าน"),
                    CurrentAddress = table.Column<string>(type: "longtext", nullable: false, comment: "ที่อยู่ปัจจุบัน")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CurrentProvinceId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    CurrentDistrictId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    CurrentSubDistrictId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    CurrentZipCode = table.Column<string>(type: "varchar(10)", maxLength: 10, nullable: false, comment: "รหัสไปรษณีย์ที่อยู่ปัจจุบัน")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Marry = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "คู่สมรส"),
                    MarryPrefixId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    MarryFirstName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "ชื่อจริงคู่สมรส")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    MarryLastName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "นามสกุลคู่สมรส")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    FatherPrefixId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    FatherFirstName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "ชื่อจริงบิดา")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    FatherLastName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "นามสกุลบิดา")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    MotherPrefixId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    MotherFirstName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "ชื่อจริงมารดา")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    MotherLastName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "นามสกุลมารดา")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    OccupationType = table.Column<string>(type: "longtext", nullable: false, comment: "ประเภทอาชีพที่ทำงานมาก่อน")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    OccupationCompany = table.Column<string>(type: "longtext", nullable: false, comment: "สำนัก/บริษัท บริษัท")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    OccupationDepartment = table.Column<string>(type: "longtext", nullable: false, comment: "กอง/ฝ่าย บริษัท")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    OccupationEmail = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "อีเมล บริษัท")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    OccupationTelephone = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false, comment: "โทรศัพท์ บริษัท")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Candidates", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Candidates_Districts_CitizenDistrictId",
                        column: x => x.CitizenDistrictId,
                        principalTable: "Districts",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_Districts_CurrentDistrictId",
                        column: x => x.CurrentDistrictId,
                        principalTable: "Districts",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_Districts_RegistDistrictId",
                        column: x => x.RegistDistrictId,
                        principalTable: "Districts",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_PeriodExams_PeriodExamId",
                        column: x => x.PeriodExamId,
                        principalTable: "PeriodExams",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Candidates_Prefixes_FatherPrefixId",
                        column: x => x.FatherPrefixId,
                        principalTable: "Prefixes",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_Prefixes_MarryPrefixId",
                        column: x => x.MarryPrefixId,
                        principalTable: "Prefixes",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_Prefixes_MotherPrefixId",
                        column: x => x.MotherPrefixId,
                        principalTable: "Prefixes",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_Prefixes_PrefixId",
                        column: x => x.PrefixId,
                        principalTable: "Prefixes",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_Provinces_CitizenProvinceId",
                        column: x => x.CitizenProvinceId,
                        principalTable: "Provinces",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_Provinces_CurrentProvinceId",
                        column: x => x.CurrentProvinceId,
                        principalTable: "Provinces",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_Provinces_RegistProvinceId",
                        column: x => x.RegistProvinceId,
                        principalTable: "Provinces",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_Relationships_RelationshipId",
                        column: x => x.RelationshipId,
                        principalTable: "Relationships",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_SubDistricts_CurrentSubDistrictId",
                        column: x => x.CurrentSubDistrictId,
                        principalTable: "SubDistricts",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Candidates_SubDistricts_RegistSubDistrictId",
                        column: x => x.RegistSubDistrictId,
                        principalTable: "SubDistricts",
                        principalColumn: "Id");
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Careers",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "PrimaryKey", collation: "ascii_general_ci"),
                    DurationStart = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "ระยะเวลาเริ่ม"),
                    DurationEnd = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "ระยะเวลาสิ้นสุด"),
                    Name = table.Column<string>(type: "longtext", nullable: false, comment: "สถานที่ทำงาน/ฝึกงาน")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Position = table.Column<string>(type: "longtext", nullable: false, comment: "ตำแหน่ง/ลักษณะงาน")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Salary = table.Column<int>(type: "int", maxLength: 20, nullable: false, comment: "เงินเดือนสุดท้ายก่อนออก"),
                    Reason = table.Column<string>(type: "longtext", nullable: false, comment: "เหตุผลที่ออก")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    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"),
                    CandidateId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Careers", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Careers_Candidates_CandidateId",
                        column: x => x.CandidateId,
                        principalTable: "Candidates",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Educations",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "PrimaryKey", collation: "ascii_general_ci"),
                    DurationStart = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "ระยะเวลาเริ่ม"),
                    DurationEnd = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "ระยะเวลาสิ้นสุด"),
                    Name = table.Column<string>(type: "longtext", nullable: false, comment: "ชื่อสถานศึกษา")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Major = table.Column<string>(type: "longtext", nullable: false, comment: "สาขาวิชา/วิชาเอก")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Scores = table.Column<int>(type: "int", maxLength: 10, nullable: false, comment: "คะแนนเฉลี่ยตลอดหลักสูตร"),
                    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"),
                    CandidateId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    EducationLevelId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Educations", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Educations_Candidates_CandidateId",
                        column: x => x.CandidateId,
                        principalTable: "Candidates",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Educations_EducationLevels_EducationLevelId",
                        column: x => x.EducationLevelId,
                        principalTable: "EducationLevels",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_CitizenDistrictId",
                table: "Candidates",
                column: "CitizenDistrictId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_CitizenProvinceId",
                table: "Candidates",
                column: "CitizenProvinceId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_CurrentDistrictId",
                table: "Candidates",
                column: "CurrentDistrictId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_CurrentProvinceId",
                table: "Candidates",
                column: "CurrentProvinceId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_CurrentSubDistrictId",
                table: "Candidates",
                column: "CurrentSubDistrictId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_FatherPrefixId",
                table: "Candidates",
                column: "FatherPrefixId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_MarryPrefixId",
                table: "Candidates",
                column: "MarryPrefixId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_MotherPrefixId",
                table: "Candidates",
                column: "MotherPrefixId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_PeriodExamId",
                table: "Candidates",
                column: "PeriodExamId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_PrefixId",
                table: "Candidates",
                column: "PrefixId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_RegistDistrictId",
                table: "Candidates",
                column: "RegistDistrictId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_RegistProvinceId",
                table: "Candidates",
                column: "RegistProvinceId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_RegistSubDistrictId",
                table: "Candidates",
                column: "RegistSubDistrictId");

            migrationBuilder.CreateIndex(
                name: "IX_Candidates_RelationshipId",
                table: "Candidates",
                column: "RelationshipId");

            migrationBuilder.CreateIndex(
                name: "IX_Careers_CandidateId",
                table: "Careers",
                column: "CandidateId");

            migrationBuilder.CreateIndex(
                name: "IX_Educations_CandidateId",
                table: "Educations",
                column: "CandidateId");

            migrationBuilder.CreateIndex(
                name: "IX_Educations_EducationLevelId",
                table: "Educations",
                column: "EducationLevelId");
        }

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

            migrationBuilder.DropTable(
                name: "Educations");

            migrationBuilder.DropTable(
                name: "Candidates");

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