using System.Collections.Generic;
using System.Linq;

namespace Valg.EVA.Skanning.ServicesModel.ElectionConfig.Model
{
    public class Affiliation
    {
        public Affiliation()
        {
            Candidates = new List<Candidate>();
        }

        
        
        
        
        public string RegisteredName { get; set; }

        
        
        
        
        public string AffiliationId { get; set; }

        
        
        
        
        
        
        
        public string AffiliationShortCode { get; set; }

        public List<Candidate> Candidates { get; private set; }
        public static readonly Affiliation Blank = new Affiliation
        {
            AffiliationId = "BLANK",
            AffiliationShortCode = "9999",
            RegisteredName = "Blank stemmeseddel",
            Candidates = new List<Candidate>()
        };

        public static bool IsProposedShortCodeBlankAffiliation(string proposedShortCode)
        {
            return proposedShortCode == Blank.AffiliationShortCode;
        }

        public bool IsBlank => AffiliationShortCode == Blank.AffiliationShortCode;

        public void SetCandidates(List<Candidate> candidateList)
        {
            Candidates = candidateList.ToList();
        }

        public bool CandidateExistsWithinTheAffiliation(int valueToTest)
        {
            return Candidates.Any(c => c.RankInAffiliation == valueToTest);
        }
    }
}
