using System.Linq;
using StubCore.Entities;
using System.Collections.Generic;

namespace StubCore.Plugins.DataCollector
{
    public class NodeValuesCollector : FrontCollector
    {

        private readonly string sourceName;
        private readonly string nodesFolder;

        public NodeValuesCollector(string name, string folder) : base(name, folder)
        {
            sourceName = name;
            nodesFolder = folder;
        }

        public List<NodeValue> GetValuesFile(int fileID)
        {
            var _fileList = new List<NodeValue>();
            var _list = GetFiles<NodeValue>();

            if (_list.Count > 0)
            {
                _fileList = (_list.Where(value => value.fileID == fileID)).ToList<NodeValue>();

                if (_fileList.Count == 0)
                {
                    _logger.NoFileValuesWasFound(fileID);
                }
            }
            else
            {
                _logger.ItemsListNotExists(nodesFolder);
            }

            return _fileList;
        }

        public List<NodeValue> GetValuesNode(int nodeID)
        {
            var _fileList = new List<NodeValue>();
            var _list = GetFiles<NodeValue>();

            if (_list.Count > 0)
            {
                _fileList = (_list.Where(value => value.nodeID == nodeID)).ToList<NodeValue>();

                if (_fileList.Count == 0)
                {
                    _logger.NoValuesFoundForNode(nodeID);
                }
            }
            else
            {
                _logger.ItemsListNotExists(nodesFolder);
            }

            return _fileList;
        }

        public List<NodeValue> GetAllValues(List<int> nodes)
        {
            var _fileList = new List<NodeValue>();
            var _list = GetFiles<NodeValue>();

            if(_list.Count > 0)
            {
                _fileList = (from value in _list where nodes.Contains(value.nodeID) select value) as List<NodeValue>;

                if (_fileList.Count == 0)
                {
                    _logger.NoValuesFoundForNodes(nodes);
                }
            }
            else
            {
                _logger.ItemsListNotExists(nodesFolder);
            }

            return _fileList;
        }

    }
}
