using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BMA.EHR.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class ChangeOrgLinktoGUID : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_InsigniaManageOrganiations_OrganizationOrganizations_Organiz~",
                table: "InsigniaManageOrganiations");

            migrationBuilder.DropForeignKey(
                name: "FK_InsigniaManageProfiles_OrganizationOrganizations_BorrowOrgan~",
                table: "InsigniaManageProfiles");

            migrationBuilder.DropForeignKey(
                name: "FK_InsigniaManageProfiles_OrganizationOrganizations_ReturnOrgan~",
                table: "InsigniaManageProfiles");

            migrationBuilder.DropIndex(
                name: "IX_InsigniaManageProfiles_BorrowOrganizationId",
                table: "InsigniaManageProfiles");

            migrationBuilder.DropIndex(
                name: "IX_InsigniaManageProfiles_ReturnOrganizationId",
                table: "InsigniaManageProfiles");

            migrationBuilder.DropIndex(
                name: "IX_InsigniaManageOrganiations_OrganizationOrganizationId",
                table: "InsigniaManageOrganiations");

            migrationBuilder.DropColumn(
                name: "OrganizationOrganizationId",
                table: "InsigniaManageOrganiations");

            migrationBuilder.AlterColumn<Guid>(
                name: "ReturnOrganizationId",
                table: "InsigniaManageProfiles",
                type: "char(36)",
                nullable: true,
                comment: "Fk Table OrganizationOrganization Return",
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true)
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "BorrowOrganizationId",
                table: "InsigniaManageProfiles",
                type: "char(36)",
                nullable: true,
                comment: "Fk Table OrganizationOrganization Borrow",
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true)
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AddColumn<Guid>(
                name: "OrganizationId",
                table: "InsigniaManageOrganiations",
                type: "char(36)",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
                comment: "รหัสหน่วยงาน",
                collation: "ascii_general_ci");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "OrganizationId",
                table: "InsigniaManageOrganiations");

            migrationBuilder.AlterColumn<Guid>(
                name: "ReturnOrganizationId",
                table: "InsigniaManageProfiles",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true,
                oldComment: "Fk Table OrganizationOrganization Return")
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "BorrowOrganizationId",
                table: "InsigniaManageProfiles",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true,
                oldComment: "Fk Table OrganizationOrganization Borrow")
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AddColumn<Guid>(
                name: "OrganizationOrganizationId",
                table: "InsigniaManageOrganiations",
                type: "char(36)",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
                collation: "ascii_general_ci");

            migrationBuilder.CreateIndex(
                name: "IX_InsigniaManageProfiles_BorrowOrganizationId",
                table: "InsigniaManageProfiles",
                column: "BorrowOrganizationId");

            migrationBuilder.CreateIndex(
                name: "IX_InsigniaManageProfiles_ReturnOrganizationId",
                table: "InsigniaManageProfiles",
                column: "ReturnOrganizationId");

            migrationBuilder.CreateIndex(
                name: "IX_InsigniaManageOrganiations_OrganizationOrganizationId",
                table: "InsigniaManageOrganiations",
                column: "OrganizationOrganizationId");

            migrationBuilder.AddForeignKey(
                name: "FK_InsigniaManageOrganiations_OrganizationOrganizations_Organiz~",
                table: "InsigniaManageOrganiations",
                column: "OrganizationOrganizationId",
                principalTable: "OrganizationOrganizations",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_InsigniaManageProfiles_OrganizationOrganizations_BorrowOrgan~",
                table: "InsigniaManageProfiles",
                column: "BorrowOrganizationId",
                principalTable: "OrganizationOrganizations",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_InsigniaManageProfiles_OrganizationOrganizations_ReturnOrgan~",
                table: "InsigniaManageProfiles",
                column: "ReturnOrganizationId",
                principalTable: "OrganizationOrganizations",
                principalColumn: "Id");
        }
    }
}
