using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Baya.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class BookingRequests : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.EnsureSchema(
                name: "booking");

            migrationBuilder.CreateTable(
                name: "BookingRequests",
                schema: "booking",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CustomerId = table.Column<long>(type: "bigint", nullable: false),
                    NurseId = table.Column<long>(type: "bigint", nullable: false),
                    PatientId = table.Column<long>(type: "bigint", nullable: false),
                    VariantId = table.Column<long>(type: "bigint", nullable: false),
                    CustomerAddressId = table.Column<long>(type: "bigint", nullable: false),
                    RequiredCaregiverGender = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: true),
                    RequestedDate = table.Column<DateOnly>(type: "date", nullable: false),
                    RequestedTimeStart = table.Column<TimeOnly>(type: "time", nullable: false),
                    RequestedTimeEnd = table.Column<TimeOnly>(type: "time", nullable: false),
                    CustomerNotes = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
                    Status = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    NurseResponseDeadlineAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    PaymentDeadlineAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    NurseRejectionReason = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    DeletedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
                    CreatedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
                    ModifiedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
                    CreatedById = table.Column<int>(type: "int", nullable: true),
                    ModifiedById = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BookingRequests", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BookingRequests_CustomerAddresses_CustomerAddressId",
                        column: x => x.CustomerAddressId,
                        principalSchema: "usr",
                        principalTable: "CustomerAddresses",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BookingRequests_CustomerProfiles_CustomerId",
                        column: x => x.CustomerId,
                        principalSchema: "usr",
                        principalTable: "CustomerProfiles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BookingRequests_NurseProfiles_NurseId",
                        column: x => x.NurseId,
                        principalSchema: "usr",
                        principalTable: "NurseProfiles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BookingRequests_NurseServiceVariants_VariantId",
                        column: x => x.VariantId,
                        principalSchema: "catalog",
                        principalTable: "NurseServiceVariants",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BookingRequests_Patients_PatientId",
                        column: x => x.PatientId,
                        principalSchema: "usr",
                        principalTable: "Patients",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_BookingRequests_CustomerAddressId",
                schema: "booking",
                table: "BookingRequests",
                column: "CustomerAddressId");

            migrationBuilder.CreateIndex(
                name: "IX_BookingRequests_CustomerId_Status",
                schema: "booking",
                table: "BookingRequests",
                columns: new[] { "CustomerId", "Status" });

            migrationBuilder.CreateIndex(
                name: "IX_BookingRequests_NurseId_Status",
                schema: "booking",
                table: "BookingRequests",
                columns: new[] { "NurseId", "Status" });

            migrationBuilder.CreateIndex(
                name: "IX_BookingRequests_PatientId",
                schema: "booking",
                table: "BookingRequests",
                column: "PatientId");

            migrationBuilder.CreateIndex(
                name: "IX_BookingRequests_Status_NurseResponseDeadlineAt",
                schema: "booking",
                table: "BookingRequests",
                columns: new[] { "Status", "NurseResponseDeadlineAt" });

            migrationBuilder.CreateIndex(
                name: "IX_BookingRequests_Status_PaymentDeadlineAt",
                schema: "booking",
                table: "BookingRequests",
                columns: new[] { "Status", "PaymentDeadlineAt" });

            migrationBuilder.CreateIndex(
                name: "IX_BookingRequests_VariantId",
                schema: "booking",
                table: "BookingRequests",
                column: "VariantId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "BookingRequests",
                schema: "booking");
        }
    }
}
