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

#nullable disable

namespace JobsMedical.Web.Migrations
{
    /// <inheritdoc />
    public partial class AddTalentListing : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "LinkedTalentId",
                table: "RawListings",
                type: "integer",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "TalentListings",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    RoleId = table.Column<int>(type: "integer", nullable: false),
                    PersonName = table.Column<string>(type: "character varying(150)", maxLength: 150, nullable: true),
                    YearsExperience = table.Column<int>(type: "integer", nullable: true),
                    IsLicensed = table.Column<bool>(type: "boolean", nullable: false),
                    CityId = table.Column<int>(type: "integer", nullable: false),
                    DistrictId = table.Column<int>(type: "integer", nullable: true),
                    AreaNote = table.Column<string>(type: "character varying(150)", maxLength: 150, nullable: true),
                    Availability = table.Column<int>(type: "integer", nullable: true),
                    Gender = table.Column<int>(type: "integer", nullable: false),
                    PayType = table.Column<int>(type: "integer", nullable: false),
                    PayAmount = table.Column<long>(type: "bigint", nullable: true),
                    SharePercent = table.Column<int>(type: "integer", nullable: true),
                    Phone = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: true),
                    Description = table.Column<string>(type: "character varying(2000)", maxLength: 2000, 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_TalentListings", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TalentListings_Cities_CityId",
                        column: x => x.CityId,
                        principalTable: "Cities",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_TalentListings_Districts_DistrictId",
                        column: x => x.DistrictId,
                        principalTable: "Districts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_TalentListings_Roles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "Roles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_TalentListings_CityId_RoleId",
                table: "TalentListings",
                columns: new[] { "CityId", "RoleId" });

            migrationBuilder.CreateIndex(
                name: "IX_TalentListings_DistrictId",
                table: "TalentListings",
                column: "DistrictId");

            migrationBuilder.CreateIndex(
                name: "IX_TalentListings_RoleId",
                table: "TalentListings",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_TalentListings_Status",
                table: "TalentListings",
                column: "Status");
        }

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

            migrationBuilder.DropColumn(
                name: "LinkedTalentId",
                table: "RawListings");
        }
    }
}
