using Microsoft.EntityFrameworkCore; using SVSim.Bootstrap.Models.Seed; using SVSim.Database; using SVSim.Database.Models; namespace SVSim.Bootstrap.Importers; /// /// Idempotent upsert of the spot card exchange catalog from seeds/spot-card-exchange.json. /// Source is the wire /spot_card_exchange/top response, extracted via /// data_dumps/scripts/extract-spot-card-exchange.py. Rows missing from the seed are /// LEFT INTACT. /// public class SpotCardExchangeImporter { public async Task ImportAsync(SVSimDbContext context, string seedDir) { string path = Path.Combine(seedDir, "spot-card-exchange.json"); var seed = SeedLoader.LoadList(path); if (seed.Count == 0) { Console.WriteLine("[SpotCardExchangeImporter] No seed rows; skipping."); return 0; } var existing = await context.SpotCardExchangeCatalog.ToDictionaryAsync(e => e.Id); int created = 0, updated = 0; foreach (var s in seed) { if (s.CardId == 0) continue; var entry = existing.TryGetValue(s.CardId, out var ex) ? ex : new SpotCardExchangeEntry { Id = s.CardId }; entry.ClassId = s.ClassId; entry.ExchangePoint = s.ExchangePoint; entry.TsRotationId = s.TsRotationId; entry.IsPreRelease = s.IsPreRelease; entry.IsEnabled = true; if (ex is null) { context.SpotCardExchangeCatalog.Add(entry); existing[s.CardId] = entry; created++; } else updated++; } await context.SaveChangesAsync(); Console.WriteLine($"[SpotCardExchangeImporter] +{created}/~{updated}"); return created + updated; } }