namespace FKGees.DocsDefinitions.Decrets;

public class KwPomylkaKasjera : IDecretsDefinition
{
    public int DocType => 51;
    public string Type => nameof(KwPomylkaKasjera);
    public List<Definition> Definitions { get; } =
    [
        new Definition("305-60-24", "WN", "[sbr]"), 
        new Definition("100-1-24", "MA", "[sbr]")
    ];
    
    public Task<List<DecretsResult>> Process(IReadOnlyList<Dok> documents)
    {
        var result = new List<DecretsResult>();

        var toProcess = documents.Where(x => x.TypDok == DocType 
                                             && x.NrDok.StartsWith("KW")
                                             && x.Tekst1() == Constants.KwTekstyDod[nameof(KwPomylkaKasjera)]);

        foreach (var dok in toProcess)
        {
            Definitions.ForEach(d =>
            {
                var item = dok.DecretKontr();
                item.Data = dok.DataPom;
                item.DataWplywu = dok.Data;
                item.Nr = dok.NrDok;
                item.Opis = dok.TekstZaCo();
                item.StronaKonta = d.AccountSide;
                item.KontoFk = d.Account;
                item.Kwota = Math.Abs(dok.Zaplacono).AsString();

                result.Add(item);
            });
        }

        return Task.FromResult(result);
    }
}