using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace esuite.Database.SqlServer.Migrations
{
    /// <inheritdoc />
    public partial class SpecificationChanges : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Specifications_FormInstances_FormInstanceId",
                schema: "Printer",
                table: "Specifications");

            migrationBuilder.DropIndex(
                name: "IX_Specifications_FormInstanceId",
                schema: "Printer",
                table: "Specifications");

            migrationBuilder.DropIndex(
                name: "IX_Specifications_SiteId_Name",
                schema: "Printer",
                table: "Specifications");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                schema: "Printer",
                table: "Specifications",
                type: "nvarchar(max)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(450)");

            migrationBuilder.AddColumn<long>(
                name: "SigmaId",
                schema: "Printer",
                table: "Specifications",
                type: "bigint",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_SsoProviders_Guid",
                schema: "UserManager",
                table: "SsoProviders",
                column: "Guid",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Specifications_SigmaId",
                schema: "Printer",
                table: "Specifications",
                column: "SigmaId",
                unique: true,
                filter: "[SigmaId] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_Specifications_SiteId",
                schema: "Printer",
                table: "Specifications",
                column: "SiteId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropIndex(
                name: "IX_SsoProviders_Guid",
                schema: "UserManager",
                table: "SsoProviders");

            migrationBuilder.DropIndex(
                name: "IX_Specifications_SigmaId",
                schema: "Printer",
                table: "Specifications");

            migrationBuilder.DropIndex(
                name: "IX_Specifications_SiteId",
                schema: "Printer",
                table: "Specifications");

            migrationBuilder.DropColumn(
                name: "SigmaId",
                schema: "Printer",
                table: "Specifications");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                schema: "Printer",
                table: "Specifications",
                type: "nvarchar(450)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)");

            migrationBuilder.CreateIndex(
                name: "IX_Specifications_FormInstanceId",
                schema: "Printer",
                table: "Specifications",
                column: "FormInstanceId");

            migrationBuilder.CreateIndex(
                name: "IX_Specifications_SiteId_Name",
                schema: "Printer",
                table: "Specifications",
                columns: ["SiteId", "Name"],
                unique: true);

            migrationBuilder.AddForeignKey(
                name: "FK_Specifications_FormInstances_FormInstanceId",
                schema: "Printer",
                table: "Specifications",
                column: "FormInstanceId",
                principalSchema: "Forms",
                principalTable: "FormInstances",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
