using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class tblTemplatesMigrationFormApplicationInWork : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_EsppSchValues_ApplicationsInWorks_ApplicationsInWorkId",
                table: "EsppSchValues");

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

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

            migrationBuilder.DropIndex(
                name: "IX_Templates_ApplicationInWorkId",
                table: "Templates");

            migrationBuilder.DropIndex(
                name: "IX_Templates_HostId",
                table: "Templates");

            migrationBuilder.DropColumn(
                name: "ApplicationInWorkId",
                table: "Templates");

            migrationBuilder.DropColumn(
                name: "HostId",
                table: "Templates");

            migrationBuilder.RenameColumn(
                name: "Duration",
                schema: "job",
                table: "Groups",
                newName: "TemplateDuration");

            migrationBuilder.RenameColumn(
                name: "ApplicationsInWorkId",
                table: "EsppSchValues",
                newName: "JobGroupId");

            migrationBuilder.AddColumn<string>(
                name: "AgentName",
                schema: "job",
                table: "Groups",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "AgentScript",
                schema: "job",
                table: "Groups",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "AgentTimeOutSec",
                schema: "job",
                table: "Groups",
                type: "integer",
                nullable: true);

            migrationBuilder.AddColumn<bool>(
                name: "IsAgent",
                schema: "job",
                table: "Groups",
                type: "boolean",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "IsAutoDistributionEnabled",
                schema: "job",
                table: "Groups",
                type: "boolean",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddForeignKey(
                name: "FK_EsppSchValues_Groups_JobGroupId",
                table: "EsppSchValues",
                column: "JobGroupId",
                principalSchema: "job",
                principalTable: "Groups",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

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

            migrationBuilder.DropColumn(
                name: "AgentName",
                schema: "job",
                table: "Groups");

            migrationBuilder.DropColumn(
                name: "AgentScript",
                schema: "job",
                table: "Groups");

            migrationBuilder.DropColumn(
                name: "AgentTimeOutSec",
                schema: "job",
                table: "Groups");

            migrationBuilder.DropColumn(
                name: "IsAgent",
                schema: "job",
                table: "Groups");

            migrationBuilder.DropColumn(
                name: "IsAutoDistributionEnabled",
                schema: "job",
                table: "Groups");

            migrationBuilder.RenameColumn(
                name: "TemplateDuration",
                schema: "job",
                table: "Groups",
                newName: "Duration");

            migrationBuilder.RenameColumn(
                name: "JobGroupId",
                table: "EsppSchValues",
                newName: "ApplicationsInWorkId");

            migrationBuilder.AddColumn<Guid>(
                name: "ApplicationInWorkId",
                table: "Templates",
                type: "uuid",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.AddColumn<Guid>(
                name: "HostId",
                table: "Templates",
                type: "uuid",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.CreateIndex(
                name: "IX_Templates_ApplicationInWorkId",
                table: "Templates",
                column: "ApplicationInWorkId");

            migrationBuilder.CreateIndex(
                name: "IX_Templates_HostId",
                table: "Templates",
                column: "HostId");

            migrationBuilder.AddForeignKey(
                name: "FK_EsppSchValues_ApplicationsInWorks_ApplicationsInWorkId",
                table: "EsppSchValues",
                column: "ApplicationsInWorkId",
                principalTable: "ApplicationsInWorks",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Templates_ApplicationsInWorks_ApplicationInWorkId",
                table: "Templates",
                column: "ApplicationInWorkId",
                principalTable: "ApplicationsInWorks",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Templates_Hosts_HostId",
                table: "Templates",
                column: "HostId",
                principalTable: "Hosts",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
