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

#nullable disable

namespace Predictalytics.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddTraderPosition : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "TraderPositions",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TraderId = table.Column<int>(type: "int", nullable: false),
                    MarketOutcomeId = table.Column<int>(type: "int", nullable: false),
                    SharesHeld = table.Column<decimal>(type: "decimal(14,6)", precision: 14, scale: 6, nullable: false),
                    AvgCost = table.Column<decimal>(type: "decimal(10,6)", precision: 10, scale: 6, nullable: false),
                    RealizedPnl = table.Column<decimal>(type: "decimal(18,4)", precision: 18, scale: 4, nullable: false),
                    LastUpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TraderPositions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TraderPositions_MarketOutcomes_MarketOutcomeId",
                        column: x => x.MarketOutcomeId,
                        principalTable: "MarketOutcomes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_TraderPositions_Traders_TraderId",
                        column: x => x.TraderId,
                        principalTable: "Traders",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_TraderPositions_MarketOutcomeId",
                table: "TraderPositions",
                column: "MarketOutcomeId");

            migrationBuilder.CreateIndex(
                name: "IX_TraderPositions_TraderId_MarketOutcomeId",
                table: "TraderPositions",
                columns: new[] { "TraderId", "MarketOutcomeId" },
                unique: true);
        }

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