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

#nullable disable

namespace TakeoutSaaS.Infrastructure.Migrations.DictionaryDb
{
    /// <inheritdoc />
    public partial class AddCacheInvalidationLogs : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "dictionary_cache_invalidation_logs",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false, comment: "实体唯一标识。")
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Timestamp = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "发生时间（UTC）。"),
                    DictionaryCode = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "字典编码。"),
                    Scope = table.Column<int>(type: "integer", nullable: false, comment: "字典作用域。"),
                    AffectedCacheKeyCount = table.Column<int>(type: "integer", nullable: false, comment: "影响的缓存键数量。"),
                    OperatorId = table.Column<long>(type: "bigint", nullable: false, comment: "操作人用户标识。"),
                    Operation = table.Column<int>(type: "integer", nullable: false, comment: "操作类型。"),
                    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_dictionary_cache_invalidation_logs", x => x.Id);
                },
                comment: "字典缓存失效日志。");

            migrationBuilder.CreateIndex(
                name: "IX_dictionary_cache_invalidation_logs_TenantId_Timestamp",
                table: "dictionary_cache_invalidation_logs",
                columns: new[] { "TenantId", "Timestamp" });
        }

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