using System.Text.Json;

namespace CalledIt.Seeder;

/// <summary>
/// Loads match data from a local football-data.org JSON file.
/// </summary>
public sealed class JsonFileMatchDataSource(string filePath) : IMatchDataSource
{
    public async Task<FootballDataResponse> LoadAsync()
    {
        await using var stream = File.OpenRead(filePath);
        return await JsonSerializer.DeserializeAsync<FootballDataResponse>(stream)
            ?? throw new InvalidOperationException($"Failed to deserialize match data from '{filePath}'.");
    }
}
