using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TakeoutSaaS.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddTenantPackagePublishAndVisibility : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<string>(
                name: "LogoUrl",
                table: "tenants",
                type: "text",
                nullable: true,
                comment: "LOGO 图片地址。",
                oldClrType: typeof(string),
                oldType: "character varying(256)",
                oldMaxLength: 256,
                oldNullable: true,
                oldComment: "LOGO 图片地址。");

            migrationBuilder.AlterColumn<bool>(
                name: "IsActive",
                table: "tenant_packages",
                type: "boolean",
                nullable: false,
                comment: "是否仍启用（平台控制）。",
                oldClrType: typeof(bool),
                oldType: "boolean",
                oldComment: "是否仍可售卖。");

            migrationBuilder.AddColumn<bool>(
                name: "IsAllowNewTenantPurchase",
                table: "tenant_packages",
                type: "boolean",
                nullable: false,
                defaultValue: true,
                comment: "是否允许新租户购买/选择（仅影响新购）。");

            migrationBuilder.AddColumn<bool>(
                name: "IsPublicVisible",
                table: "tenant_packages",
                type: "boolean",
                nullable: false,
                defaultValue: true,
                comment: "是否对外可见（展示页/套餐列表可见性）。");

            migrationBuilder.AddColumn<int>(
                name: "PublishStatus",
                table: "tenant_packages",
                type: "integer",
                nullable: false,
                defaultValue: 1,
                comment: "发布状态：0=草稿，1=已发布。");

            migrationBuilder.CreateIndex(
                name: "IX_tenant_packages_PublishStatus_IsActive_IsPublicVisible_IsAl~",
                table: "tenant_packages",
                columns: new[] { "PublishStatus", "IsActive", "IsPublicVisible", "IsAllowNewTenantPurchase", "SortOrder" });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropIndex(
                name: "IX_tenant_packages_PublishStatus_IsActive_IsPublicVisible_IsAl~",
                table: "tenant_packages");

            migrationBuilder.DropColumn(
                name: "IsAllowNewTenantPurchase",
                table: "tenant_packages");

            migrationBuilder.DropColumn(
                name: "IsPublicVisible",
                table: "tenant_packages");

            migrationBuilder.DropColumn(
                name: "PublishStatus",
                table: "tenant_packages");

            migrationBuilder.AlterColumn<string>(
                name: "LogoUrl",
                table: "tenants",
                type: "character varying(256)",
                maxLength: 256,
                nullable: true,
                comment: "LOGO 图片地址。",
                oldClrType: typeof(string),
                oldType: "text",
                oldNullable: true,
                oldComment: "LOGO 图片地址。");

            migrationBuilder.AlterColumn<bool>(
                name: "IsActive",
                table: "tenant_packages",
                type: "boolean",
                nullable: false,
                comment: "是否仍可售卖。",
                oldClrType: typeof(bool),
                oldType: "boolean",
                oldComment: "是否仍启用（平台控制）。");
        }
    }
}
