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.PracticeChoice;

    [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) {
            if(Utility.IsAPIKeyValid(apiKey)) {
                var authToken = (string)this.Session[SessionKeys.AuthToken];
                var terminology = new PlutoServer.PracticeChoice.Core.Terminology();

                var termList = terminology.SearchTerminology(authToken, searchString, searchType, terminologyDomain);
                return termList.ToArray();
            } else {
                return null;
            }
        }

        #endregion
    }
}