﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Roster.Logic.RatioCalculation.OneRatioRules
{
    abstract class RuleBase
    {
        //MAX

        protected bool Max8Infants(Dictionary<int, int> dist)
        {
            return MaxInfants(8, dist);
        }

        protected bool Max7Infants(Dictionary<int, int> dist)
        {
            return MaxInfants(7, dist);
        }

        protected bool Max5Infants(Dictionary<int, int> dist)
        {
            return MaxInfants(5, dist);
        }

        protected bool Max3Infants(Dictionary<int, int> dist)
        {
            return MaxInfants(3, dist);
        }

        //Excact

        protected bool Has8Infants(Dictionary<int, int> d)
        {
            return HasSpecificNrOfInfants(8, d);
        }

        protected bool Has7Infants(Dictionary<int, int> d)
        {
            return HasSpecificNrOfInfants(7, d);
        }

        protected bool Has6Infants(Dictionary<int, int> d)
        {
            return HasSpecificNrOfInfants(6, d);
        }

        protected bool Has4Infants(Dictionary<int, int> d)
        {
            return HasSpecificNrOfInfants(4, d);
        }
        
        private bool MaxInfants(int limit, Dictionary<int, int> dist)
        {
            int count;
            dist.TryGetValue(0, out count);
            return count <= limit;
        }

        private bool HasSpecificNrOfInfants(int excactMatch, Dictionary<int, int> d)
        {
            int count;
            d.TryGetValue(0, out count);
            return count == excactMatch;
        }
    }
}
