namespace FKGees.DocsDefinitions.Decrets;

public class KwKaucjaZDokUtargu : IDecretsDefinition
{
    public int DocType => 53;
    public string Type => nameof(KwKaucjaZDokUtargu);
    public List<Definition> Definitions { get; } =
    [
        new Definition("100-1-24", "MA", "[sbr]"), 
        new Definition("139-1-24", "WN", "[sbr]")
    ];

    public Task<List<DecretsResult>> Process(IReadOnlyList<Dok> documents)
    {
        var result = new List<DecretsResult>();

        var toProcess = documents
            .Where(x => x.TypDok == DocType && x.Kwota2 != 0)
            .GroupBy(x => x.Data);
    

        foreach (var dok in toProcess)
        {
            Definitions.ForEach(d =>
            {
                var item = new DecretsResult
                {
                    Data = dok.Key,
                    DataWplywu = dok.Key,
                    Nr = string.Join(", ",dok.Select(z => z.NrDok)),
                    Opis = "KAUCJA ZA OPAKOWANIA-ZWROT",
                    StronaKonta = d.AccountSide,
                    KontoFk = d.Account,
                    Kwota = dok.Sum(x => x.Kwota2).AsString()
                };

                result.Add(item);
            });
        }

        return Task.FromResult(result);
    }
}