using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Ropin.Inspection.Model.Migrations
{
    public partial class EditPNT : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "TPNT_Area",
                columns: table => new
                {
                    C_Code = table.Column<Guid>(type: "char(36)", nullable: false),
                    C_StoreCode = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: false),
                    C_Name = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", maxLength: 255, nullable: false),
                    C_SName = table.Column<string>(type: "varchar(16) CHARACTER SET utf8mb4", maxLength: 16, nullable: true),
                    C_ImageUrl = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", maxLength: 255, nullable: true),
                    I_Sort = table.Column<int>(type: "int", nullable: false),
                    C_Remark = table.Column<string>(type: "varchar(500) CHARACTER SET utf8mb4", maxLength: 500, nullable: true),
                    C_CreateBy = table.Column<Guid>(type: "char(36)", nullable: false),
                    D_CreateOn = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    C_LastUpdatedBy = table.Column<Guid>(type: "char(36)", nullable: true),
                    D_LastUpdatedOn = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    C_Status = table.Column<string>(type: "varchar(1) CHARACTER SET utf8mb4", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TPNT_Area", x => x.C_Code);
                    table.ForeignKey(
                        name: "FK_TPNT_Area_TSYS_User_C_CreateBy",
                        column: x => x.C_CreateBy,
                        principalTable: "TSYS_User",
                        principalColumn: "C_UserID",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_TPNT_Area_TSYS_User_C_LastUpdatedBy",
                        column: x => x.C_LastUpdatedBy,
                        principalTable: "TSYS_User",
                        principalColumn: "C_UserID",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "TPNT_Store",
                columns: table => new
                {
                    C_ID = table.Column<Guid>(type: "char(36)", nullable: false),
                    C_LicenseCode = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: false),
                    C_AreaCode = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: true),
                    C_Code = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: false),
                    C_Name = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", maxLength: 255, nullable: false),
                    C_SName = table.Column<string>(type: "varchar(16) CHARACTER SET utf8mb4", maxLength: 16, nullable: true),
                    C_TypeCode = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: false),
                    C_Address = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: true),
                    C_GPS = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: true),
                    I_Sort = table.Column<int>(type: "int", nullable: false),
                    C_Remark = table.Column<string>(type: "varchar(500) CHARACTER SET utf8mb4", maxLength: 500, nullable: true),
                    C_CreateBy = table.Column<Guid>(type: "char(36)", nullable: false),
                    D_CreateOn = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    C_LastUpdatedBy = table.Column<Guid>(type: "char(36)", nullable: true),
                    D_LastUpdatedOn = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    C_Status = table.Column<string>(type: "varchar(1) CHARACTER SET utf8mb4", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TPNT_Store", x => x.C_ID);
                    table.ForeignKey(
                        name: "FK_TPNT_Store_TBDM_Area_C_AreaCode",
                        column: x => x.C_AreaCode,
                        principalTable: "TBDM_Area",
                        principalColumn: "C_Code",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_TPNT_Store_TSYS_User_C_CreateBy",
                        column: x => x.C_CreateBy,
                        principalTable: "TSYS_User",
                        principalColumn: "C_UserID",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_TPNT_Store_TSYS_User_C_LastUpdatedBy",
                        column: x => x.C_LastUpdatedBy,
                        principalTable: "TSYS_User",
                        principalColumn: "C_UserID",
                        onDelete: ReferentialAction.Restrict);
                    //table.ForeignKey(
                    //  name: "FK_TSYS_LicenseTPNT_Store_Code",
                    //  column: x => x.C_LicenseCode,
                    //  principalTable: "TSYS_License",
                    //  principalColumn: "C_Code",
                    //  onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "TPNT_StoreOrg",
                columns: table => new
                {
                    C_StoreCode = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: false),
                    C_OrgCode = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: false),
                    C_CreateBy = table.Column<Guid>(type: "char(36)", nullable: false),
                    D_CreateOn = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TPNT_StoreOrg", x => new { x.C_StoreCode, x.C_OrgCode });
                    table.ForeignKey(
                        name: "FK_TPNT_StoreOrg_TSYS_User_C_CreateBy",
                        column: x => x.C_CreateBy,
                        principalTable: "TSYS_User",
                        principalColumn: "C_UserID",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "TPNT_Type",
                columns: table => new
                {
                    C_Code = table.Column<Guid>(type: "char(36)", nullable: false),
                    C_Name = table.Column<string>(type: "varchar(50) CHARACTER SET utf8mb4", maxLength: 50, nullable: false),
                    I_Sort = table.Column<int>(type: "int", nullable: false),
                    C_Status = table.Column<string>(type: "varchar(1) CHARACTER SET utf8mb4", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TPNT_Type", x => x.C_Code);
                });

            migrationBuilder.CreateIndex(
                name: "IX_TPNT_Area_C_CreateBy",
                table: "TPNT_Area",
                column: "C_CreateBy");

            migrationBuilder.CreateIndex(
                name: "IX_TPNT_Area_C_LastUpdatedBy",
                table: "TPNT_Area",
                column: "C_LastUpdatedBy");

            migrationBuilder.CreateIndex(
                name: "IX_TPNT_Store_C_AreaCode",
                table: "TPNT_Store",
                column: "C_AreaCode");

            migrationBuilder.CreateIndex(
                name: "IX_TPNT_Store_C_CreateBy",
                table: "TPNT_Store",
                column: "C_CreateBy");

            migrationBuilder.CreateIndex(
                name: "IX_TPNT_Store_C_LastUpdatedBy",
                table: "TPNT_Store",
                column: "C_LastUpdatedBy");

            migrationBuilder.CreateIndex(
                name: "IX_TPNT_StoreOrg_C_CreateBy",
                table: "TPNT_StoreOrg",
                column: "C_CreateBy");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "TPNT_Area");

            migrationBuilder.DropTable(
                name: "TPNT_Store");

            migrationBuilder.DropTable(
                name: "TPNT_StoreOrg");

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