using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace JobsMedical.Web.Migrations
{
    /// <inheritdoc />
    public partial class JobsAndAuth : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<int>(
                name: "ShiftId",
                table: "InterestEvents",
                type: "integer",
                nullable: true,
                oldClrType: typeof(int),
                oldType: "integer");

            migrationBuilder.AddColumn<int>(
                name: "JobOpeningId",
                table: "InterestEvents",
                type: "integer",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "JobOpenings",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    FacilityId = table.Column<int>(type: "integer", nullable: false),
                    RoleId = table.Column<int>(type: "integer", nullable: false),
                    Title = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
                    EmploymentType = table.Column<int>(type: "integer", nullable: false),
                    SalaryMin = table.Column<long>(type: "bigint", nullable: true),
                    SalaryMax = table.Column<long>(type: "bigint", nullable: true),
                    Description = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
                    Requirements = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
                    Status = table.Column<int>(type: "integer", nullable: false),
                    Source = table.Column<int>(type: "integer", nullable: false),
                    SourceUrl = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_JobOpenings", x => x.Id);
                    table.ForeignKey(
                        name: "FK_JobOpenings_Facilities_FacilityId",
                        column: x => x.FacilityId,
                        principalTable: "Facilities",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_JobOpenings_Roles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "Roles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_InterestEvents_JobOpeningId",
                table: "InterestEvents",
                column: "JobOpeningId");

            migrationBuilder.CreateIndex(
                name: "IX_JobOpenings_FacilityId",
                table: "JobOpenings",
                column: "FacilityId");

            migrationBuilder.CreateIndex(
                name: "IX_JobOpenings_RoleId",
                table: "JobOpenings",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_JobOpenings_Status",
                table: "JobOpenings",
                column: "Status");

            migrationBuilder.AddForeignKey(
                name: "FK_InterestEvents_JobOpenings_JobOpeningId",
                table: "InterestEvents",
                column: "JobOpeningId",
                principalTable: "JobOpenings",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_InterestEvents_JobOpenings_JobOpeningId",
                table: "InterestEvents");

            migrationBuilder.DropTable(
                name: "JobOpenings");

            migrationBuilder.DropIndex(
                name: "IX_InterestEvents_JobOpeningId",
                table: "InterestEvents");

            migrationBuilder.DropColumn(
                name: "JobOpeningId",
                table: "InterestEvents");

            migrationBuilder.AlterColumn<int>(
                name: "ShiftId",
                table: "InterestEvents",
                type: "integer",
                nullable: false,
                defaultValue: 0,
                oldClrType: typeof(int),
                oldType: "integer",
                oldNullable: true);
        }
    }
}
