using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace VigilCareClinicalAPI.Migrations
{
    /// <inheritdoc />
    public partial class AddOutboxRetryColumns : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropIndex(
                name: "IX_outbox_events_created_at",
                table: "outbox_events");

            migrationBuilder.AddColumn<DateTimeOffset>(
                name: "failed_at",
                table: "outbox_events",
                type: "timestamp with time zone",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "last_error",
                table: "outbox_events",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "retry_count",
                table: "outbox_events",
                type: "integer",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateIndex(
                name: "IX_outbox_events_created_at",
                table: "outbox_events",
                column: "created_at",
                filter: "processed_at IS NULL AND failed_at IS NULL");
        }

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

            migrationBuilder.DropColumn(
                name: "failed_at",
                table: "outbox_events");

            migrationBuilder.DropColumn(
                name: "last_error",
                table: "outbox_events");

            migrationBuilder.DropColumn(
                name: "retry_count",
                table: "outbox_events");

            migrationBuilder.CreateIndex(
                name: "IX_outbox_events_created_at",
                table: "outbox_events",
                column: "created_at",
                filter: "processed_at IS NULL");
        }
    }
}
