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

namespace Elwig.Documents {
    public class MemberDataSheet : BusinessDocument {

        public new static string Name => "Stammdatenblatt";

        public Season Season;
        public Dictionary<string, MemberBucket> MemberBuckets;
        public IEnumerable<AreaCom> ActiveAreaCommitments;

        public MemberDataSheet(Member m, AppDbContext ctx) : base($"{Name} {m.AdministrativeName}", m) {
            DocumentId = $"{Name} {m.MgNr}";
            Season = ctx.Seasons.ToList().MaxBy(s => s.Year) ?? throw new ArgumentException("invalid season");
            MemberBuckets = ctx.GetMemberBuckets(Utils.CurrentYear, m.MgNr).GetAwaiter().GetResult();
            ActiveAreaCommitments = m.ActiveAreaCommitments(ctx);
        }
    }
}
