using System.Net;
using System.Net.Http.Json;
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using SVSim.Database;
using SVSim.Database.Enums;
using SVSim.Database.Models;
using SVSim.UnitTests.Infrastructure;
namespace SVSim.UnitTests.Controllers;
///
/// Bracket-end /finish + /retire coverage. Locks the wire shape (rewards + reward_list +
/// colosseum_status) and verifies side-effects: rewards granted through the inventory
/// service, run row deleted, champion flag flipped on final-round clear.
///
public class ArenaColosseumControllerBracketTerminateTests
{
private static readonly object Envelope =
new { viewer_id = "0", steam_id = 0, steam_session_ticket = "" };
/// Three-round config with reward bundles on every round + a champion bundle.
private static async Task ActivateSeasonWithRewardsAsync(SVSimTestFactory factory)
{
using var scope = factory.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService();
var seasonJson = JsonSerializer.Serialize(new
{
IsColosseumPeriod = true,
SeasonId = 42,
ColosseumName = "Test Cup",
DeckFormat = (int)Format.Rotation,
FinalRoundEliminateCount = 1000,
});
await UpsertConfigAsync(db, "ColosseumSeason", seasonJson);
var roundsJson = JsonSerializer.Serialize(new
{
Rounds = new[]
{
new
{
RoundId = 1,
Groups = new[] { new { Group = "", MaxBattleCount = 5, BreakthroughNumber = 3, EntryNumber = 100_000 } },
FinishRewards = new[]
{
new { Type = (int)UserGoodsType.Crystal, DetailId = 0L, Count = 100, Name = "R1 finish" },
},
RetireRewards = new object[]
{
new { Type = (int)UserGoodsType.Rupy, DetailId = 0L, Count = 50, Name = "R1 retire" },
},
},
new
{
RoundId = 2,
Groups = new[] { new { Group = "Group A", MaxBattleCount = 5, BreakthroughNumber = 4, EntryNumber = 10_000 } },
FinishRewards = new[]
{
new { Type = (int)UserGoodsType.Crystal, DetailId = 0L, Count = 250, Name = "R2 finish" },
},
RetireRewards = Array.Empty