using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

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

            migrationBuilder.RenameColumn(
                name: "OrderStatusCode",
                table: "Orders",
                newName: "StatusCode");

            migrationBuilder.RenameIndex(
                name: "IX_Orders_OrderStatusCode",
                table: "Orders",
                newName: "IX_Orders_StatusCode");

            migrationBuilder.AddColumn<int>(
                name: "NextStatusCode",
                table: "Orders",
                type: "integer",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_Orders_NextStatusCode",
                table: "Orders",
                column: "NextStatusCode");

            migrationBuilder.AddForeignKey(
                name: "FK_Orders_OrderStatuses_NextStatusCode",
                table: "Orders",
                column: "NextStatusCode",
                principalTable: "OrderStatuses",
                principalColumn: "Code");

            migrationBuilder.AddForeignKey(
                name: "FK_Orders_OrderStatuses_StatusCode",
                table: "Orders",
                column: "StatusCode",
                principalTable: "OrderStatuses",
                principalColumn: "Code",
                onDelete: ReferentialAction.Cascade);
        }

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

            migrationBuilder.DropForeignKey(
                name: "FK_Orders_OrderStatuses_StatusCode",
                table: "Orders");

            migrationBuilder.DropIndex(
                name: "IX_Orders_NextStatusCode",
                table: "Orders");

            migrationBuilder.DropColumn(
                name: "NextStatusCode",
                table: "Orders");

            migrationBuilder.RenameColumn(
                name: "StatusCode",
                table: "Orders",
                newName: "OrderStatusCode");

            migrationBuilder.RenameIndex(
                name: "IX_Orders_StatusCode",
                table: "Orders",
                newName: "IX_Orders_OrderStatusCode");

            migrationBuilder.AddForeignKey(
                name: "FK_Orders_OrderStatuses_OrderStatusCode",
                table: "Orders",
                column: "OrderStatusCode",
                principalTable: "OrderStatuses",
                principalColumn: "Code",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
