using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class JobsUpdateMOCKData : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_FieldFilters_JobUnitFilters_UnitFilterId",
                schema: "job",
                table: "FieldFilters");

            migrationBuilder.DropForeignKey(
                name: "FK_JobUnitFilters_Jobs_JobId",
                schema: "job",
                table: "JobUnitFilters");

            migrationBuilder.DropForeignKey(
                name: "FK_Templates_Jobs_JobId",
                table: "Templates");

            migrationBuilder.DropForeignKey(
                name: "FK_Templates_Units_UnitId",
                table: "Templates");

            migrationBuilder.DropPrimaryKey(
                name: "PK_JobUnitFilters",
                schema: "job",
                table: "JobUnitFilters");

            migrationBuilder.RenameTable(
                name: "JobUnitFilters",
                schema: "job",
                newName: "UnitFilters",
                newSchema: "job");

            migrationBuilder.RenameIndex(
                name: "IX_JobUnitFilters_JobId",
                schema: "job",
                table: "UnitFilters",
                newName: "IX_UnitFilters_JobId");

            migrationBuilder.AlterColumn<Guid>(
                name: "UnitId",
                table: "Templates",
                type: "uuid",
                nullable: false,
                defaultValue: new Guid("b4dfd71a-2b2f-414f-8409-4b9abd9c4d2c"),
                oldClrType: typeof(Guid),
                oldType: "uuid",
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "JobId",
                table: "Templates",
                type: "uuid",
                nullable: false,
                defaultValue: new Guid("ba05948b-b040-48cc-ab77-0accc9c223a0"),
                oldClrType: typeof(Guid),
                oldType: "uuid",
                oldNullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_UnitFilters",
                schema: "job",
                table: "UnitFilters",
                column: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_FieldFilters_UnitFilters_UnitFilterId",
                schema: "job",
                table: "FieldFilters",
                column: "UnitFilterId",
                principalSchema: "job",
                principalTable: "UnitFilters",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Templates_Jobs_JobId",
                table: "Templates",
                column: "JobId",
                principalSchema: "job",
                principalTable: "Jobs",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Templates_Units_UnitId",
                table: "Templates",
                column: "UnitId",
                principalSchema: "unit",
                principalTable: "Units",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_UnitFilters_Jobs_JobId",
                schema: "job",
                table: "UnitFilters",
                column: "JobId",
                principalSchema: "job",
                principalTable: "Jobs",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_FieldFilters_UnitFilters_UnitFilterId",
                schema: "job",
                table: "FieldFilters");

            migrationBuilder.DropForeignKey(
                name: "FK_Templates_Jobs_JobId",
                table: "Templates");

            migrationBuilder.DropForeignKey(
                name: "FK_Templates_Units_UnitId",
                table: "Templates");

            migrationBuilder.DropForeignKey(
                name: "FK_UnitFilters_Jobs_JobId",
                schema: "job",
                table: "UnitFilters");

            migrationBuilder.DropPrimaryKey(
                name: "PK_UnitFilters",
                schema: "job",
                table: "UnitFilters");

            migrationBuilder.RenameTable(
                name: "UnitFilters",
                schema: "job",
                newName: "JobUnitFilters",
                newSchema: "job");

            migrationBuilder.RenameIndex(
                name: "IX_UnitFilters_JobId",
                schema: "job",
                table: "JobUnitFilters",
                newName: "IX_JobUnitFilters_JobId");

            migrationBuilder.AlterColumn<Guid>(
                name: "UnitId",
                table: "Templates",
                type: "uuid",
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uuid");

            migrationBuilder.AlterColumn<Guid>(
                name: "JobId",
                table: "Templates",
                type: "uuid",
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uuid");

            migrationBuilder.AddPrimaryKey(
                name: "PK_JobUnitFilters",
                schema: "job",
                table: "JobUnitFilters",
                column: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_FieldFilters_JobUnitFilters_UnitFilterId",
                schema: "job",
                table: "FieldFilters",
                column: "UnitFilterId",
                principalSchema: "job",
                principalTable: "JobUnitFilters",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_JobUnitFilters_Jobs_JobId",
                schema: "job",
                table: "JobUnitFilters",
                column: "JobId",
                principalSchema: "job",
                principalTable: "Jobs",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Templates_Jobs_JobId",
                table: "Templates",
                column: "JobId",
                principalSchema: "job",
                principalTable: "Jobs",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Templates_Units_UnitId",
                table: "Templates",
                column: "UnitId",
                principalSchema: "unit",
                principalTable: "Units",
                principalColumn: "Id");
        }
    }
}
