using Campaign_Tracker.Server.LegacyData.Models; namespace Campaign_Tracker.Server.LegacyData; /// /// In-memory implementation of for use in /// development environments without an Access database, and as the test double /// for integration tests. /// /// Accepts seeded collections via constructor so tests can inject specific /// records without coupling to file-system or network state. /// public sealed class InMemoryLegacyDataAccess : ILegacyDataAccess { private readonly IReadOnlyList _jurisdictions; private readonly IReadOnlyList _contacts; private readonly IReadOnlyList _kits; private readonly IReadOnlyList _kitLabels; public InMemoryLegacyDataAccess( IReadOnlyList? jurisdictions = null, IReadOnlyList? contacts = null, IReadOnlyList? kits = null, IReadOnlyList? kitLabels = null) { _jurisdictions = jurisdictions ?? DefaultJurisdictions; _contacts = contacts ?? DefaultContacts; _kits = kits ?? DefaultKits; _kitLabels = kitLabels ?? DefaultKitLabels; } // ── Jurisdiction ────────────────────────────────────────────────────────── public Task GetJurisdictionAsync( string jCode, CancellationToken cancellationToken = default) { var result = _jurisdictions.FirstOrDefault(j => string.Equals(j.JCode, jCode, StringComparison.OrdinalIgnoreCase)); return Task.FromResult(result); } public Task> GetAllJurisdictionsAsync( CancellationToken cancellationToken = default) => Task.FromResult(_jurisdictions); // ── Contact ─────────────────────────────────────────────────────────────── public Task GetContactByIdAsync( int id, CancellationToken cancellationToken = default) { var result = _contacts.FirstOrDefault(c => c.Id == id); return Task.FromResult(result); } public Task> GetContactsByJurisdictionAsync( string jCode, CancellationToken cancellationToken = default) { IReadOnlyList result = _contacts .Where(c => string.Equals(c.JurisCode, jCode, StringComparison.OrdinalIgnoreCase)) .ToList(); return Task.FromResult(result); } // ── Kit ─────────────────────────────────────────────────────────────────── public Task GetKitByIdAsync( int id, CancellationToken cancellationToken = default) { var result = _kits.FirstOrDefault(k => k.Id == id); return Task.FromResult(result); } public Task> GetKitsByJurisdictionAsync( string jCode, CancellationToken cancellationToken = default) { IReadOnlyList result = _kits .Where(k => string.Equals(k.JCode, jCode, StringComparison.OrdinalIgnoreCase)) .ToList(); return Task.FromResult(result); } // ── KitLabel ────────────────────────────────────────────────────────────── public Task> GetKitLabelsByKitAsync( int kitId, CancellationToken cancellationToken = default) { IReadOnlyList result = _kitLabels .Where(l => l.KitId == kitId) .ToList(); return Task.FromResult(result); } // ── Default seed data (representative dev/test records) ────────────────── private static readonly IReadOnlyList DefaultJurisdictions = [ new("FAIR01", "Fairview Borough", "100 Main St", "Fairview, PA 16415", null, null), new("LAKE02", "Lake Township", "200 Lake Rd", "Lake City, PA 16423", null, null), new("PINE03", "Pine County", "300 Pine Ave", "Edinboro, PA 16412", null, null), ]; private static readonly IReadOnlyList DefaultContacts = [ new(1, "FAIR01", "Jane Doe", "Election Director", "jdoe@fairview.gov", "814-555-0101", null, "100 Main St", null, "Fairview, PA 16415", null, null, null, "Fairview Borough", "01"), new(2, "LAKE02", "John Smith", "Clerk", "jsmith@laketownship.gov", "814-555-0202", "814-555-0203", "200 Lake Rd", null, "Lake City, PA 16423", null, null, null, "Lake Township", "02"), ]; private static readonly IReadOnlyList DefaultKits = [ new(101, "FAIR01", "JOB-2026-001", "Inkjet", "Active", "fair01_primary_2026.mdb", Cass: true, InkJetJob: true, CreatedOn: new DateTime(2026, 3, 1, 0, 0, 0, DateTimeKind.Utc), ExportedToSnailWorks: null, LabelsPrinted: null, OfficeCopiesAmount: 50, InboundStid: "STI001", OutboundStid: "STO001"), new(102, "LAKE02", "JOB-2026-002", "OfficeCopy", "Pending", null, Cass: false, InkJetJob: false, CreatedOn: new DateTime(2026, 3, 5, 0, 0, 0, DateTimeKind.Utc), ExportedToSnailWorks: null, LabelsPrinted: null, OfficeCopiesAmount: 25, InboundStid: null, OutboundStid: null), ]; private static readonly IReadOnlyList DefaultKitLabels = [ new(201, KitId: 101, InBoundImb: "0041234500012345678", InBoundImbDigits: "01-234-56789-12", InBoundSerial: "SN001", OutboundImb: "0041234500098765432", OutboundImbDigits: "01-234-56789-98", OutboundSerial: "SN002", SetNumber: 1), new(202, KitId: 101, InBoundImb: "0041234500022345678", InBoundImbDigits: "01-234-56789-22", InBoundSerial: "SN003", OutboundImb: "0041234500088765432", OutboundImbDigits: "01-234-56789-88", OutboundSerial: "SN004", SetNumber: 2), ]; }