using System.Text.Json;

namespace KiMailOrderAgent.Catalog;

public class JsonArticleCatalogService : IArticleCatalogService
{
    private readonly string _filePath = "articles.json";

    public async Task<List<Article>> GetArticlesAsync(CancellationToken cancellationToken)
    {
        if (!File.Exists(_filePath))
            return new List<Article>();

        var json = await File.ReadAllTextAsync(_filePath, cancellationToken);

        return JsonSerializer.Deserialize<List<Article>>(json, new JsonSerializerOptions
        {
            PropertyNameCaseInsensitive = true
        }) ?? new List<Article>();
    }
}
