using System.Xml;
using System.Xml.Linq;
using Newtonsoft.Json;
using StubCore.Plugins.Helpers;
using System.Collections.Generic;
using StubCore.Plugins.DataOperations;

namespace StubCore.Plugins.QueryOperations
{
    public class QueryData
    {

        private string _profile;
        private List<string> _files;
        private bool notEmpty;
        /*
        public QDataOperations _qhelper = new QDataOperations();

        /// <summary>
        /// Class constructor. Operate with simple/certain request.
        /// </summary>
        /// <param name="profile">Name of current profile</param>
        /// <param name="inputFileString">String of names for current profile</param>
        /// <remarks>
        /// Last changed: 12.10.2015
        /// Author: Mikhael Aktsyzniy
        /// </remarks>
        public QueryData(string profile, string inputFileString)
        {
            this._profile = profile;
            this._files = this.CheckFilesList(inputFileString);
            this.notEmpty = _qhelper.ValidateProfileData(profile, this._files);

            if (this.notEmpty)
            {
                this._qhelper.SetProfile(this._profile);
            }

        }

        /// <summary>
        /// Initializing the process of file/content validation and operation with it
        /// </summary>
        /// <returns>Response with data or error</returns>
        /// <remarks>
        /// Last changed: 08.10.2015
        /// Author: Mikhael Aktsyzniy
        /// </remarks>
        public object InitResponse()
        {
            ODataResponse _odata = new ODataResponse();
            _odata.SetMessage("Some data of request is missed");

            if (this.notEmpty)
            {
                _odata.ResetEssense(_qhelper.GetFileByRequest(this._files));
                
                if(_odata._opr.isCompleted == true)
                {
                    var result = XElement.Parse(_odata._opr.message);

                    switch (this._qhelper._profile.transportType)
                    {
                        case "json":
                            var xmlDoc = new XmlDocument();
                            xmlDoc.LoadXml(result.ToString());
                            return JsonConvert.SerializeXmlNode(xmlDoc.DocumentElement);
                        default:
                            return this._qhelper.ValidateResponse(result);
                    }
                }
            }

            return _odata._opr;
        }

        /// <summary>
        /// Check file string and separate it for file names
        /// </summary>
        /// <param name="files">String of files</param>
        /// <returns>List with file names</returns>
        /// <remarks>
        /// Last changed: 12.10.2015
        /// Author: Mikhael Aktsyzniy
        /// </remarks>
        public List<string> CheckFilesList(string files)
        {
            List<string> _list = new List<string>(files.Split(','));
            return _list;
        }

    */
    }
}
