using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace TakeoutSaaS.Infrastructure.Migrations.IdentityDb
{
    /// <inheritdoc />
    public partial class AddMenuDefinitions : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "menu_definitions",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false, comment: "实体唯一标识。")
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    ParentId = table.Column<long>(type: "bigint", nullable: false, comment: "父级菜单 ID，根节点为 0。"),
                    Name = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "菜单名称（前端路由 name）。"),
                    Path = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false, comment: "路由路径。"),
                    Component = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false, comment: "组件路径（不含 .vue）。"),
                    Title = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false, comment: "标题。"),
                    Icon = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "图标标识。"),
                    IsIframe = table.Column<bool>(type: "boolean", nullable: false, comment: "是否 iframe。"),
                    Link = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true, comment: "外链或 iframe 地址。"),
                    KeepAlive = table.Column<bool>(type: "boolean", nullable: false, comment: "是否缓存。"),
                    SortOrder = table.Column<int>(type: "integer", nullable: false, comment: "排序。"),
                    RequiredPermissions = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false, comment: "访问该菜单所需的权限集合（逗号分隔）。"),
                    MetaPermissions = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false, comment: "Meta.permissions（逗号分隔）。"),
                    MetaRoles = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false, comment: "Meta.roles（逗号分隔）。"),
                    AuthListJson = table.Column<string>(type: "text", nullable: true, comment: "按钮权限列表 JSON（存储 MenuAuthItemDto 数组）。"),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间（UTC）。"),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "最近一次更新时间（UTC），从未更新时为 null。"),
                    DeletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "软删除时间（UTC），未删除时为 null。"),
                    CreatedBy = table.Column<long>(type: "bigint", nullable: true, comment: "创建人用户标识，匿名或系统操作时为 null。"),
                    UpdatedBy = table.Column<long>(type: "bigint", nullable: true, comment: "最后更新人用户标识，匿名或系统操作时为 null。"),
                    DeletedBy = table.Column<long>(type: "bigint", nullable: true, comment: "删除人用户标识（软删除），未删除时为 null。"),
                    TenantId = table.Column<long>(type: "bigint", nullable: false, comment: "所属租户 ID。")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_menu_definitions", x => x.Id);
                },
                comment: "管理端菜单定义。");

            migrationBuilder.CreateIndex(
                name: "IX_menu_definitions_TenantId_ParentId_SortOrder",
                table: "menu_definitions",
                columns: new[] { "TenantId", "ParentId", "SortOrder" });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "menu_definitions");
        }
    }
}
