using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace ColaFlow.Modules.Identity.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class AddEmailRateLimitsTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "email_rate_limits",
                schema: "identity",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    email = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
                    tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
                    operation_type = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    last_sent_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    attempts_count = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_email_rate_limits", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "ix_email_rate_limits_email_tenant_operation",
                schema: "identity",
                table: "email_rate_limits",
                columns: new[] { "email", "tenant_id", "operation_type" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "ix_email_rate_limits_last_sent_at",
                schema: "identity",
                table: "email_rate_limits",
                column: "last_sent_at");
        }

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