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

namespace ReGen
{
    public class DocumentResults
    {
        private SortedDictionary<String, SortedDictionary<String, List<String>>> m_DocumentResults = new SortedDictionary<String, SortedDictionary<String, List<String>>>();

        public void SetDocumentResults(String DocumentName, SortedDictionary<String, List<String>> Results)
        {
            if (!String.IsNullOrWhiteSpace(DocumentName) && (null != Results))
            {
                if (null != m_DocumentResults)
                {
                    try
                    {
                        if (m_DocumentResults.ContainsKey(DocumentName))
                        {
                            m_DocumentResults[DocumentName] = Results;
                        }
                        else
                        {
                            m_DocumentResults.Add(DocumentName, Results);
                        }
                    }
                    catch
                    {

                    }
                }
            }
        }

        public SortedDictionary<String, List<String>> GetDocumentResults(String DocumentName)
        {
            SortedDictionary<String, List<String>> Results = null;

            try
            {
                if (!String.IsNullOrWhiteSpace(DocumentName))
                {
                    if (null != m_DocumentResults)
                    {
                        try
                        {
                            if (m_DocumentResults.ContainsKey(DocumentName))
                            {
                                Results = m_DocumentResults[DocumentName];
                            }
                        }
                        catch
                        {
                            Results = null;
                        }
                    }
                }
            }
            catch
            {
                Results = null;
            }

            return Results;
        }

        public void Clear()
        {
            try
            {
                m_DocumentResults.Clear();
            }
            catch
            {

            }
        }

        public bool Empty()
        {
            bool IsEmpty = true;

            try
            {
                if (0 != m_DocumentResults.Count)
                {
                    IsEmpty = false;
                }
            }
            catch
            {
                IsEmpty = true;
            }

            return IsEmpty;
        }

        public void SetResultsForStudy(String DocumentName, String StudyName, List<String> Results)
        {
            if (!String.IsNullOrWhiteSpace(DocumentName) && !String.IsNullOrWhiteSpace(StudyName) && (null != Results))
            {
                if (null != m_DocumentResults)
                {
                    try
                    {
                        if (m_DocumentResults.ContainsKey(DocumentName))
                        {
                            if (m_DocumentResults[DocumentName].ContainsKey(StudyName))
                            {
                                m_DocumentResults[DocumentName][StudyName] = Results;
                            }
                            else
                            {
                                m_DocumentResults[DocumentName].Add(StudyName, Results);
                            }
                        }
                        else
                        {
                            SortedDictionary<String, List<String>> DocumentStudyResults = new SortedDictionary<String, List<String>>();

                            if (null != DocumentStudyResults)
                            {
                                DocumentStudyResults.Add(StudyName, Results);

                                m_DocumentResults.Add(DocumentName, DocumentStudyResults);
                            }
                        }
                    }
                    catch
                    {

                    }
                }
            }
        }
    }
}
