using Elwig.Helpers;
using Elwig.Helpers.Billing;
using Elwig.Models.Dtos;
using Elwig.Models.Entities;
using System.Collections.Generic;
using System.Linq;

namespace Elwig.Documents {
    public class PaymentVariantSummary : Document {

        public new static string Name => "Auszahlungsvariante";

        public PaymentVariantSummaryData Data;
        public PaymentVar Variant;
        public BillingData BillingData;
        public string CurrencySymbol;
        public int MemberNum;
        public int DeliveryNum;
        public int DeliveryPartNum;
        public List<ModifierStat> ModifierStat;
        public Dictionary<string, Modifier> Modifiers;

        public PaymentVariantSummary(PaymentVar v, PaymentVariantSummaryData data) :
            base($"{Name} {v.Year} - {v.Name}") {
            Variant = v;
            BillingData = BillingData.FromJson(v.Data);
            Data = data;
            CurrencySymbol = v.Season.Currency.Symbol ?? v.Season.Currency.Code;
            MemberNum = v.Credits.Count;
            IsPreview = MemberNum == 0;
            DeliveryNum = v.DeliveryPartPayments.DistinctBy(p => p.DeliveryPart.Delivery).Count();
            DeliveryPartNum = v.DeliveryPartPayments.Count;
            ModifierStat = AppDbContext.GetModifierStats(v.Year, v.AvNr).GetAwaiter().GetResult();
            Modifiers = v.Season.Modifiers.ToDictionary(m => m.ModId);
        }
    }
}
