using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace SolutionErp.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class AddWorkflowApps : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Attendances",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UserFullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    AttendanceDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CheckInAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CheckOutAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CheckInLatitude = table.Column<decimal>(type: "decimal(10,7)", nullable: true),
                    CheckInLongitude = table.Column<decimal>(type: "decimal(10,7)", nullable: true),
                    CheckInAccuracy = table.Column<decimal>(type: "decimal(8,2)", nullable: true),
                    CheckOutLatitude = table.Column<decimal>(type: "decimal(10,7)", nullable: true),
                    CheckOutLongitude = table.Column<decimal>(type: "decimal(10,7)", nullable: true),
                    CheckOutAccuracy = table.Column<decimal>(type: "decimal(8,2)", nullable: true),
                    SourceIn = table.Column<int>(type: "int", nullable: false),
                    SourceOut = table.Column<int>(type: "int", nullable: false),
                    IpAddressIn = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    IpAddressOut = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Note = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    WorkHours = table.Column<decimal>(type: "decimal(5,2)", nullable: true),
                    OtHours = table.Column<decimal>(type: "decimal(5,2)", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Attendances", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ItTickets",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MaTicket = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    RequesterUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RequesterFullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    Title = table.Column<string>(type: "nvarchar(300)", maxLength: 300, nullable: false),
                    Description = table.Column<string>(type: "nvarchar(max)", maxLength: 5000, nullable: false),
                    Category = table.Column<int>(type: "int", nullable: false),
                    Priority = table.Column<int>(type: "int", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    AssignedToUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    AssignedToFullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    ResolvedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Resolution = table.Column<string>(type: "nvarchar(max)", maxLength: 5000, nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ItTickets", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "LeaveRequests",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MaDonTu = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    RequesterUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RequesterFullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    LeaveTypeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    StartDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    EndDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    NumDays = table.Column<decimal>(type: "decimal(5,2)", nullable: false),
                    Reason = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    ApprovalWorkflowId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    CurrentApprovalLevelOrder = table.Column<int>(type: "int", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_LeaveRequests", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "OtRequests",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MaDonTu = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    RequesterUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RequesterFullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    OtDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    StartTime = table.Column<TimeSpan>(type: "time", nullable: false),
                    EndTime = table.Column<TimeSpan>(type: "time", nullable: false),
                    Hours = table.Column<decimal>(type: "decimal(5,2)", nullable: false),
                    Reason = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: false),
                    OtPolicyId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Status = table.Column<int>(type: "int", nullable: false),
                    ApprovalWorkflowId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    CurrentApprovalLevelOrder = table.Column<int>(type: "int", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtRequests", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "TravelRequests",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MaDonTu = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    RequesterUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RequesterFullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    Destination = table.Column<string>(type: "nvarchar(300)", maxLength: 300, nullable: false),
                    StartDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    EndDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    NumDays = table.Column<int>(type: "int", nullable: false),
                    Purpose = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: false),
                    EstimatedCost = table.Column<decimal>(type: "decimal(18,2)", nullable: true),
                    Status = table.Column<int>(type: "int", nullable: false),
                    ApprovalWorkflowId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    CurrentApprovalLevelOrder = table.Column<int>(type: "int", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TravelRequests", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "VehicleBookings",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MaDonTu = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    RequesterUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RequesterFullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    VehicleLicense = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    VehicleName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    StartAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    EndAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Destination = table.Column<string>(type: "nvarchar(300)", maxLength: 300, nullable: false),
                    Purpose = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: false),
                    DriverName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    Status = table.Column<int>(type: "int", nullable: false),
                    ApprovalWorkflowId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    CurrentApprovalLevelOrder = table.Column<int>(type: "int", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_VehicleBookings", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Attendances_UserId_AttendanceDate",
                table: "Attendances",
                columns: new[] { "UserId", "AttendanceDate" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ItTickets_AssignedToUserId",
                table: "ItTickets",
                column: "AssignedToUserId");

            migrationBuilder.CreateIndex(
                name: "IX_ItTickets_Category",
                table: "ItTickets",
                column: "Category");

            migrationBuilder.CreateIndex(
                name: "IX_ItTickets_MaTicket",
                table: "ItTickets",
                column: "MaTicket",
                unique: true,
                filter: "[MaTicket] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_ItTickets_RequesterUserId",
                table: "ItTickets",
                column: "RequesterUserId");

            migrationBuilder.CreateIndex(
                name: "IX_ItTickets_Status",
                table: "ItTickets",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_LeaveRequests_MaDonTu",
                table: "LeaveRequests",
                column: "MaDonTu",
                unique: true,
                filter: "[MaDonTu] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_LeaveRequests_RequesterUserId",
                table: "LeaveRequests",
                column: "RequesterUserId");

            migrationBuilder.CreateIndex(
                name: "IX_LeaveRequests_Status",
                table: "LeaveRequests",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_OtRequests_MaDonTu",
                table: "OtRequests",
                column: "MaDonTu",
                unique: true,
                filter: "[MaDonTu] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_OtRequests_RequesterUserId",
                table: "OtRequests",
                column: "RequesterUserId");

            migrationBuilder.CreateIndex(
                name: "IX_OtRequests_Status",
                table: "OtRequests",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_TravelRequests_MaDonTu",
                table: "TravelRequests",
                column: "MaDonTu",
                unique: true,
                filter: "[MaDonTu] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_TravelRequests_RequesterUserId",
                table: "TravelRequests",
                column: "RequesterUserId");

            migrationBuilder.CreateIndex(
                name: "IX_TravelRequests_Status",
                table: "TravelRequests",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_VehicleBookings_MaDonTu",
                table: "VehicleBookings",
                column: "MaDonTu",
                unique: true,
                filter: "[MaDonTu] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_VehicleBookings_RequesterUserId",
                table: "VehicleBookings",
                column: "RequesterUserId");

            migrationBuilder.CreateIndex(
                name: "IX_VehicleBookings_Status",
                table: "VehicleBookings",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_VehicleBookings_VehicleLicense_StartAt",
                table: "VehicleBookings",
                columns: new[] { "VehicleLicense", "StartAt" });
        }

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

            migrationBuilder.DropTable(
                name: "ItTickets");

            migrationBuilder.DropTable(
                name: "LeaveRequests");

            migrationBuilder.DropTable(
                name: "OtRequests");

            migrationBuilder.DropTable(
                name: "TravelRequests");

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