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

#nullable disable

namespace TakeoutSaaS.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddTenantReviewClaim : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "tenant_review_claims",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false, comment: "实体唯一标识。")
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    TenantId = table.Column<long>(type: "bigint", nullable: false, comment: "被领取的租户 ID。"),
                    ClaimedBy = table.Column<long>(type: "bigint", nullable: false, comment: "领取人用户 ID。"),
                    ClaimedByName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "领取人名称（展示用快照）。"),
                    ClaimedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "领取时间（UTC）。"),
                    ReleasedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "释放时间（UTC），未释放时为 null。"),
                    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。")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tenant_review_claims", x => x.Id);
                },
                comment: "租户入驻审核领取记录（防止多管理员并发审核）。");

            migrationBuilder.CreateIndex(
                name: "IX_tenant_review_claims_ClaimedBy",
                table: "tenant_review_claims",
                column: "ClaimedBy");

            migrationBuilder.CreateIndex(
                name: "IX_tenant_review_claims_TenantId",
                table: "tenant_review_claims",
                column: "TenantId",
                unique: true,
                filter: "\"ReleasedAt\" IS NULL AND \"DeletedAt\" IS NULL");
        }

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