using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Predictalytics.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddTraderPositionHistoryGuards : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<bool>(
                name: "IsHistoryPruned",
                table: "TraderPositions",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<DateTime>(
                name: "LastTradeExecutedAt",
                table: "TraderPositions",
                type: "datetime(6)",
                nullable: true);

            // Step 2.1: Global Reset to force re-calculation of all positions and fix corrupted PnL data
            migrationBuilder.Sql("UPDATE TraderPositions SET LastAppliedTradeId = 0;");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "IsHistoryPruned",
                table: "TraderPositions");

            migrationBuilder.DropColumn(
                name: "LastTradeExecutedAt",
                table: "TraderPositions");
        }
    }
}
