public bool WithdrawCard(ICard card, int currentDay)
        {
            DepartmentResources dr = GetResourcesForType(card.type);

            if (!dr.Cards.Remove(card))
            {
                return(false);
            }
            int sum = 0;

            if (card is ICardWithParameters cardP)
            {
                sum = cardP.GetSumByParam(DepartmentParameter);
                RemoveResourceFromDetecting(card, currentDay);
            }
            else if (card is IExpendable cardE)
            {
                sum = cardE.Amount;
            }
            if (sum != 0)
            {
                dr.General   -= sum;
                dr.Available -= sum;
                ResourcesChanged(dr);
            }
            return(true);
        }
        public DepartmentResources GetResourcesForType(CardType type, bool create = false)
        {
            DepartmentResources dr = _resourcesCards.SingleOrDefault(c => c.Type == type);

            if (dr == null && create)
            {
                dr = new DepartmentResources();
                _resourcesCards.Add(dr);
                dr.Type = type;
            }
            return(dr);
        }
        public void ReleaseResource(ICard card)
        {
            IHoldable           cardH = card as IHoldable;
            ICardWithParameters cardP = card as ICardWithParameters;
            DepartmentResources dr    = GetResourcesForType(card.type);

            if (dr != null && cardH != null && cardP != null && dr.Cards.SingleOrDefault(c => c == card) != null)
            {
                int sum = cardP.GetSumByParam(DepartmentParameter);
                dr.Available += sum;
                ResourcesChanged(dr);
                cardH.Release();
            }
        }
        public void OccupyResource(ICard card)
        {
            IHoldable           cardH = card as IHoldable;
            ICardWithParameters cardP = card as ICardWithParameters;
            DepartmentResources rc    = GetResourcesForType(card.type);

            if (rc != null && cardH != null && cardP != null && rc.Cards.SingleOrDefault(c => c == card) != null)
            {
                int sum = cardP.GetSumByParam(DepartmentParameter);
                rc.Available -= sum;
                ResourcesChanged(rc);
                cardH.Hold();
            }
        }
        public List <ICard> GetAvailableResources(CardType type)
        {
            DepartmentResources dr     = GetResourcesForType(type);
            List <ICard>        result = new List <ICard>();

            if (dr == null)
            {
                return(result);
            }
            foreach (ICard c in dr.Cards)
            {
                if (c is IHoldable cardH)
                {
                    if (cardH.Available)
                    {
                        result.Add(c);
                    }
                }
            }
            return(result);
        }
        public void OccupyAmountedResources()
        {
            if (_consumablesCards.Count == 0)
            {
                return;
            }
            DepartmentResources   dr            = GetResourcesForType(_consumablesCards[0].type);
            List <ConsumableCard> cardsToDelete = new List <ConsumableCard>();

            foreach (ConsumableToExpend cons in CurrentConsExpending.ExpendList)
            {
                int rest = cons.Spended;
                foreach (ConsumableCard card in _consumablesCards)
                {
                    if (rest <= 0)
                    {
                        break;
                    }
                    if (card.ConsumableData == cons.Resource)
                    {
                        int minAmount = Math.Min(card.Amount, rest);
                        card.Expend(minAmount);
                        rest -= minAmount;
                        //need to call remove card in display?
                        if (card.Amount == 0)
                        {
                            cardsToDelete.Add(card);
                        }
                    }
                }
                foreach (ConsumableCard card in cardsToDelete)
                {
                    dr.Cards.Remove(card);
                }
            }
            ResourcesChanged(dr);
            CurrentConsExpending = null;
        }
        public void AddCard(ICard card, int currentDay)
        {
            DepartmentResources dr = GetResourcesForType(card.type, true);

            dr.Cards.Add(card);

            int sum = 0;

            if (card is ICardWithParameters cardP)
            {
                sum = cardP.GetSumByParam(DepartmentParameter);
                AddResourceToDetect(card, currentDay);
            }
            else if (card is IExpendable cardE)
            {
                sum = cardE.Amount;
            }
            if (sum != 0)
            {
                dr.General   += sum;
                dr.Available += sum;
                ResourcesChanged(dr);
            }
        }
        //***RESOURCES***//
        public bool HasCard(ICard card)
        {
            DepartmentResources dr = GetResourcesForType(card.type);

            return(dr == null ? false : dr.Cards.Contains(card));
        }