namespace Pluto.Api {
    using System;
    using RemObjects.SDK;
    using RemObjects.SDK.Types;
    using RemObjects.SDK.Server;
    using RemObjects.SDK.Server.ClassFactories;
    using System.Linq;
    using System.Collections.Generic;
    using PlutoServer.MSL;
    using PlutoServer.MSL.Connectors;

    [RemObjects.SDK.Server.ClassFactories.StandardClassFactory()]
    [RemObjects.SDK.Server.Service(Name = "Terminology", InvokerClass = typeof(Terminology_Invoker), ActivatorClass = typeof(Terminology_Activator))]
    public class Terminology : RemObjects.SDK.Server.Service, ITerminology {
        private System.ComponentModel.Container components = null;
        public Terminology() :
            base() {
            this.InitializeComponent();
        }
        private void InitializeComponent() {
        }
        protected override void Dispose(bool aDisposing) {
            if(aDisposing) {
                if((this.components != null)) {
                    this.components.Dispose();
                }
            }
            base.Dispose(aDisposing);
        }

        #region ITerminology Members

        public TerminologyInfo1[] SearchTerminology(string apiKey, string searchString, TerminologySearchTypeEnum searchType, TerminologyDomainEnum terminologyDomain, string chartID) 
        {
            bool bDoDiagnosisSearch = (terminologyDomain == TerminologyDomainEnum.DiagnosesAll);
            bool bDoProceduresSearch = (terminologyDomain == TerminologyDomainEnum.ProceduresAll);

            if (ProductType.IsKeyLytec(apiKey))
            {
                if(bDoDiagnosisSearch)
                   return LytecConnector.GetDiagnosisList(apiKey, searchString);
                if(bDoProceduresSearch)
                   return LytecConnector.GetProceduresList(apiKey, chartID, searchString);
            }
            else if (ProductType.IsKeyMedisoft(apiKey))
            {
                if (bDoDiagnosisSearch)
                    return MedisoftConnector.GetDiagnosisList(apiKey, searchString);
                if (bDoProceduresSearch)
                    return MedisoftConnector.GetProceduresList(apiKey, chartID, searchString);
            }

            // Something Failed
            return null;            
        }

        #endregion
    }
}