using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace esuite.Database.SqlServer.Migrations
{
    /// <inheritdoc />
    public partial class ChangesToSitesTables : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropIndex(
                name: "IX_Sites_Id",
                schema: "Printer",
                table: "Sites");

            migrationBuilder.DropPrimaryKey(
                name: "PK_SiteContacts",
                schema: "Printer",
                table: "SiteContacts");

            migrationBuilder.DropIndex(
                name: "IX_SiteContacts_SiteId",
                schema: "Printer",
                table: "SiteContacts");

            migrationBuilder.DropPrimaryKey(
                name: "PK_OrganisationContacts",
                schema: "Printer",
                table: "OrganisationContacts");

            migrationBuilder.DropIndex(
                name: "IX_OrganisationContacts_OrganisationId",
                schema: "Printer",
                table: "OrganisationContacts");

            migrationBuilder.DropColumn(
                name: "Id",
                schema: "Printer",
                table: "SiteContacts");

            migrationBuilder.DropColumn(
                name: "Id",
                schema: "Printer",
                table: "OrganisationContacts");

            migrationBuilder.AddColumn<bool>(
                name: "Primary",
                schema: "Printer",
                table: "SiteContacts",
                type: "bit",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "Primary",
                schema: "Printer",
                table: "OrganisationContacts",
                type: "bit",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddPrimaryKey(
                name: "PK_SiteContacts",
                schema: "Printer",
                table: "SiteContacts",
                columns: new[] { "SiteId", "ContactId" });

            migrationBuilder.AddPrimaryKey(
                name: "PK_OrganisationContacts",
                schema: "Printer",
                table: "OrganisationContacts",
                columns: new[] { "OrganisationId", "ContactId" });

            migrationBuilder.UpdateData(
                schema: "UserManager",
                table: "Users",
                keyColumn: "Id",
                keyValue: 1L,
                column: "Guid",
                value: new Guid("9f0a5037-44a9-45cf-8025-d5ae65f5f9b9"));
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropPrimaryKey(
                name: "PK_SiteContacts",
                schema: "Printer",
                table: "SiteContacts");

            migrationBuilder.DropPrimaryKey(
                name: "PK_OrganisationContacts",
                schema: "Printer",
                table: "OrganisationContacts");

            migrationBuilder.DropColumn(
                name: "Primary",
                schema: "Printer",
                table: "SiteContacts");

            migrationBuilder.DropColumn(
                name: "Primary",
                schema: "Printer",
                table: "OrganisationContacts");

            migrationBuilder.AddColumn<long>(
                name: "Id",
                schema: "Printer",
                table: "SiteContacts",
                type: "bigint",
                nullable: false,
                defaultValue: 0L)
                .Annotation("SqlServer:Identity", "1, 1");

            migrationBuilder.AddColumn<long>(
                name: "Id",
                schema: "Printer",
                table: "OrganisationContacts",
                type: "bigint",
                nullable: false,
                defaultValue: 0L)
                .Annotation("SqlServer:Identity", "1, 1");

            migrationBuilder.AddPrimaryKey(
                name: "PK_SiteContacts",
                schema: "Printer",
                table: "SiteContacts",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_OrganisationContacts",
                schema: "Printer",
                table: "OrganisationContacts",
                column: "Id");

            migrationBuilder.UpdateData(
                schema: "UserManager",
                table: "Users",
                keyColumn: "Id",
                keyValue: 1L,
                column: "Guid",
                value: new Guid("00bc6d95-2e7e-43c9-8455-d0270ca2f2d7"));

            migrationBuilder.CreateIndex(
                name: "IX_Sites_Id",
                schema: "Printer",
                table: "Sites",
                column: "Id",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_SiteContacts_SiteId",
                schema: "Printer",
                table: "SiteContacts",
                column: "SiteId");

            migrationBuilder.CreateIndex(
                name: "IX_OrganisationContacts_OrganisationId",
                schema: "Printer",
                table: "OrganisationContacts",
                column: "OrganisationId");
        }
    }
}
