using System.Text.Json; using Microsoft.EntityFrameworkCore; using SVSim.Bootstrap.Models.Seed; using SVSim.Database; using SVSim.Database.Models; namespace SVSim.Bootstrap.Importers; /// /// Singleton upsert (Id=1) of the active Take Two arena season config from /// seeds/arena-season.json. format_info is preserved verbatim as a jsonb blob. /// public class ArenaSeasonImporter { public async Task ImportAsync(SVSimDbContext context, string seedDir) { var s = SeedLoader.LoadObject(Path.Combine(seedDir, "arena-season.json")); if (s is null) return 0; var existing = await context.ArenaSeasons.FirstOrDefaultAsync(e => e.Id == 1); var entry = existing ?? new ArenaSeasonConfig { Id = 1 }; entry.Mode = s.Mode; entry.Enable = s.Enable; entry.Cost = s.Cost; entry.RupyCost = s.RupyCost; entry.TicketCost = s.TicketCost; entry.IsJoin = s.IsJoin; entry.FormatInfo = s.FormatInfo.ValueKind == JsonValueKind.Undefined ? "{}" : JsonSerializer.Serialize(s.FormatInfo); if (existing is null) context.ArenaSeasons.Add(entry); await context.SaveChangesAsync(); Console.WriteLine($"[ArenaSeasonImporter] {(existing is null ? "+1" : "~1")}"); return 1; } }