using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace LISWebAPI.Migrations
{
    public partial class Initial : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "LIS_CFG_LabMachine",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    MachinedCode = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    MachinedName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Manufacture = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    MachineDescription = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ParserName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Remarks = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsActive = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_LIS_CFG_LabMachine", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "LAB_LIS_ComponentMaster",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    MachineId = table.Column<int>(type: "int", nullable: false),
                    TestName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    DisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsActive = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_LAB_LIS_ComponentMaster", x => x.Id);
                    table.ForeignKey(
                        name: "FK_LAB_LIS_ComponentMaster_LIS_CFG_LabMachine_MachineId",
                        column: x => x.MachineId,
                        principalTable: "LIS_CFG_LabMachine",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "LAB_LIS_SampleData",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    MachineId = table.Column<int>(type: "int", nullable: false),
                    DateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    BarCodeNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Fluid = table.Column<int>(type: "int", nullable: false),
                    Quadrant = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Cup = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    TrayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    StatFlag = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ControlFlag = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Mode = table.Column<int>(type: "int", nullable: false),
                    DilutionFactor = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsActive = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_LAB_LIS_SampleData", x => x.Id);
                    table.ForeignKey(
                        name: "FK_LAB_LIS_SampleData_LIS_CFG_LabMachine_MachineId",
                        column: x => x.MachineId,
                        principalTable: "LIS_CFG_LabMachine",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "LAB_LIS_SampleResult",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    LisSampleId = table.Column<int>(type: "int", nullable: true),
                    MachineId = table.Column<int>(type: "int", nullable: false),
                    ComponentMasterId = table.Column<int>(type: "int", nullable: false),
                    Test = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Value = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Unit = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ErrorFlag = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Error = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    WarningFlag = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Warning = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    BarCodeNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsSync = table.Column<bool>(type: "bit", nullable: false),
                    IsActive = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_LAB_LIS_SampleResult", x => x.Id);
                    table.ForeignKey(
                        name: "FK_LAB_LIS_SampleResult_LAB_LIS_SampleData_LisSampleId",
                        column: x => x.LisSampleId,
                        principalTable: "LAB_LIS_SampleData",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_LAB_LIS_SampleResult_LIS_CFG_LabMachine_MachineId",
                        column: x => x.MachineId,
                        principalTable: "LIS_CFG_LabMachine",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_LAB_LIS_ComponentMaster_MachineId",
                table: "LAB_LIS_ComponentMaster",
                column: "MachineId");

            migrationBuilder.CreateIndex(
                name: "IX_LAB_LIS_SampleData_MachineId",
                table: "LAB_LIS_SampleData",
                column: "MachineId");

            migrationBuilder.CreateIndex(
                name: "IX_LAB_LIS_SampleResult_LisSampleId",
                table: "LAB_LIS_SampleResult",
                column: "LisSampleId");

            migrationBuilder.CreateIndex(
                name: "IX_LAB_LIS_SampleResult_MachineId",
                table: "LAB_LIS_SampleResult",
                column: "MachineId");
        }

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

            migrationBuilder.DropTable(
                name: "LAB_LIS_SampleResult");

            migrationBuilder.DropTable(
                name: "LAB_LIS_SampleData");

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