using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace foodmarket.Infrastructure.Persistence.Migrations
{
    /// <summary>Заменяем products.IsWeighed (bool) на products.Packaging (int enum):
    /// 1=Piece, 2=Weight, 3=Liquid. Штучный по умолчанию.</summary>
    public partial class Phase4b_ProductPackaging : Migration
    {
        protected override void Up(MigrationBuilder b)
        {
            b.AddColumn<int>(
                name: "Packaging", schema: "public", table: "products",
                type: "integer", nullable: false, defaultValue: 1);

            // Backfill: IsWeighed=true → Weight, иначе Piece.
            b.Sql("""UPDATE public.products SET "Packaging" = CASE WHEN "IsWeighed" THEN 2 ELSE 1 END;""");

            b.DropColumn(name: "IsWeighed", schema: "public", table: "products");
        }

        protected override void Down(MigrationBuilder b)
        {
            b.AddColumn<bool>(
                name: "IsWeighed", schema: "public", table: "products",
                type: "boolean", nullable: false, defaultValue: false);
            b.Sql("""UPDATE public.products SET "IsWeighed" = ("Packaging" = 2);""");
            b.DropColumn(name: "Packaging", schema: "public", table: "products");
        }
    }
}
