using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace MTWorkHR.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class contractTbls : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Contracts",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeleteUserId = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    ContractTypeId = table.Column<int>(type: "int", nullable: false),
                    CompanyId = table.Column<long>(type: "bigint", nullable: false),
                    CompanyRepresentativeId = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    UserId = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    JobId = table.Column<int>(type: "int", nullable: true),
                    AcademicQualificationId = table.Column<int>(type: "int", nullable: true),
                    SpecializationId = table.Column<int>(type: "int", nullable: true),
                    WorkCountryId = table.Column<int>(type: "int", nullable: false),
                    WorkStateId = table.Column<int>(type: "int", nullable: false),
                    JobTitleId = table.Column<int>(type: "int", nullable: true),
                    JobDescription = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    JobNumber = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: true),
                    StartDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    EndDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ContractDurationId = table.Column<int>(type: "int", nullable: false),
                    TypeOfWork = table.Column<int>(type: "int", nullable: false),
                    VacationDays = table.Column<int>(type: "int", nullable: false),
                    TrialPeriod = table.Column<int>(type: "int", nullable: false),
                    WhoCanTerminateContractInTrial = table.Column<int>(type: "int", nullable: false),
                    WhoCanTerminateContract = table.Column<int>(type: "int", nullable: false),
                    NoticePeriodBeforeTermination = table.Column<int>(type: "int", nullable: false),
                    WorkingDays = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    WorkingHours = table.Column<int>(type: "int", nullable: false),
                    StartDailyWorkingHours = table.Column<DateTime>(type: "datetime2", nullable: true),
                    EndDailyWorkingHours = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Currency = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Salary = table.Column<decimal>(type: "decimal(18,2)", nullable: true),
                    BillingCycle = table.Column<int>(type: "int", nullable: false),
                    IncludesAllAllowances = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Contracts", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ContractAllowance",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ContractId = table.Column<long>(type: "bigint", nullable: false),
                    AllowanceType = table.Column<long>(type: "bigint", nullable: false),
                    AllowanceDesc = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    EntitlementPercent = table.Column<long>(type: "bigint", nullable: false),
                    EntitlementAmount = table.Column<long>(type: "bigint", nullable: false),
                    PaymentType = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ContractAllowance", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ContractAllowance_Contracts_ContractId",
                        column: x => x.ContractId,
                        principalTable: "Contracts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ContractTask",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ContractId = table.Column<long>(type: "bigint", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(250)", maxLength: 250, nullable: false),
                    StartDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Amount = table.Column<decimal>(type: "decimal(18,2)", nullable: true),
                    ScopeOfWork = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ContractTask", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ContractTask_Contracts_ContractId",
                        column: x => x.ContractId,
                        principalTable: "Contracts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ProjectStage",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ContractId = table.Column<long>(type: "bigint", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(250)", maxLength: 250, nullable: false),
                    StartDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ExpectedEndDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    AmountPercent = table.Column<decimal>(type: "decimal(18,2)", nullable: true),
                    ScopeOfWork = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProjectStage", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ProjectStage_Contracts_ContractId",
                        column: x => x.ContractId,
                        principalTable: "Contracts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ContractTaskAttachment",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ContractTaskId = table.Column<long>(type: "bigint", nullable: false),
                    AttachmentTypeId = table.Column<long>(type: "bigint", nullable: true),
                    FileName = table.Column<string>(type: "nvarchar(250)", maxLength: 250, nullable: true),
                    OriginalName = table.Column<string>(type: "nvarchar(250)", maxLength: 250, nullable: true),
                    Content = table.Column<byte[]>(type: "varbinary(max)", nullable: false),
                    FilePath = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ContentType = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ContractTaskAttachment", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ContractTaskAttachment_AttachmentTypes_AttachmentTypeId",
                        column: x => x.AttachmentTypeId,
                        principalTable: "AttachmentTypes",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_ContractTaskAttachment_ContractTask_ContractTaskId",
                        column: x => x.ContractTaskId,
                        principalTable: "ContractTask",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ProjectStageAttachment",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ProjectStageId = table.Column<long>(type: "bigint", nullable: false),
                    AttachmentTypeId = table.Column<long>(type: "bigint", nullable: true),
                    FileName = table.Column<string>(type: "nvarchar(250)", maxLength: 250, nullable: true),
                    OriginalName = table.Column<string>(type: "nvarchar(250)", maxLength: 250, nullable: true),
                    Content = table.Column<byte[]>(type: "varbinary(max)", nullable: false),
                    FilePath = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ContentType = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProjectStageAttachment", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ProjectStageAttachment_AttachmentTypes_AttachmentTypeId",
                        column: x => x.AttachmentTypeId,
                        principalTable: "AttachmentTypes",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_ProjectStageAttachment_ProjectStage_ProjectStageId",
                        column: x => x.ProjectStageId,
                        principalTable: "ProjectStage",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_ContractAllowance_ContractId",
                table: "ContractAllowance",
                column: "ContractId");

            migrationBuilder.CreateIndex(
                name: "IX_Contracts_CompanyId",
                table: "Contracts",
                column: "CompanyId");

            migrationBuilder.CreateIndex(
                name: "IX_ContractTask_ContractId",
                table: "ContractTask",
                column: "ContractId");

            migrationBuilder.CreateIndex(
                name: "IX_ContractTaskAttachment_AttachmentTypeId",
                table: "ContractTaskAttachment",
                column: "AttachmentTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_ContractTaskAttachment_ContractTaskId",
                table: "ContractTaskAttachment",
                column: "ContractTaskId");

            migrationBuilder.CreateIndex(
                name: "IX_ProjectStage_ContractId",
                table: "ProjectStage",
                column: "ContractId");

            migrationBuilder.CreateIndex(
                name: "IX_ProjectStageAttachment_AttachmentTypeId",
                table: "ProjectStageAttachment",
                column: "AttachmentTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_ProjectStageAttachment_ProjectStageId",
                table: "ProjectStageAttachment",
                column: "ProjectStageId");
        }

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

            migrationBuilder.DropTable(
                name: "ContractTaskAttachment");

            migrationBuilder.DropTable(
                name: "ProjectStageAttachment");

            migrationBuilder.DropTable(
                name: "ContractTask");

            migrationBuilder.DropTable(
                name: "ProjectStage");

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