namespace Pluto.Api {
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using PlutoServer.MSL;
    using PlutoServer.MSL.Connectors;

    [RemObjects.SDK.Server.ClassFactories.StandardClassFactory()]
    [RemObjects.SDK.Server.Service(Name = "Practice", InvokerClass = typeof(Practice_Invoker), ActivatorClass = typeof(Practice_Activator))]
    public class Practice : RemObjects.SDK.Server.Service, IPractice {
        private System.ComponentModel.Container components = null;
        public Practice() :
            base() {
            this.InitializeComponent();
        }

        private void InitializeComponent() {            
        }

        protected override void Dispose(bool aDisposing) {
            if(aDisposing) {
                if((this.components != null)) {
                    this.components.Dispose();
                }
            }
            base.Dispose(aDisposing);
        }

        public virtual PracticeInfo1[] GetPracticeList1(string apiKey) 
        {          
            // Not supported for current SystemApiKey Structure.
            // Each ApiKey binds to one specific practice
            return null;
        }

        public virtual ProviderInfo1[] GetProviderList1(string apiKey, PracticeInfo1 practiceInfo) 
        {
            if (ProductType.IsKeyLytec(apiKey))
            {
                return LytecConnector.GetProviderList(apiKey);
            }
            else if (ProductType.IsKeyMedisoft(apiKey))
            {
                return MedisoftConnector.GetProviderList(apiKey);
            }

            MSLSpecific.Logger.Error("Invalid Product");
            return null;
        }

        #region IPractice Members

        public virtual PatientInfo1[] GetPatientList1(string apiKey, string lastName, string firstName, string dateOfBirth) 
        {
            if (ProductType.IsKeyLytec(apiKey))
            {
                return LytecConnector.GetPatientList(apiKey, lastName, firstName, dateOfBirth);
            }
            else if (ProductType.IsKeyMedisoft(apiKey))
            {
                return MedisoftConnector.GetPatientList(apiKey, lastName, firstName, dateOfBirth);
            }

            MSLSpecific.Logger.Error("Invalid Product");
            return null;                                    
        }

        public virtual MessageRecipientInfo1[] GetMessageRecipientList(string apiKey) 
        {
            return null;        
        }

        public virtual FacilityInfo1[] GetFacilitiesList1(string apiKey)
        {
            if (ProductType.IsKeyLytec(apiKey))
            {
                return LytecConnector.GetFacilitiesList(apiKey);
            }
            else if (ProductType.IsKeyMedisoft(apiKey))
            {
                return MedisoftConnector.GetFacilitiesList(apiKey);
            }

            MSLSpecific.Logger.Error("Invalid Product");
            return null;
        }

        public virtual ResourceInfo1[] GetResourcesList1(string apiKey)
        {
            if (ProductType.IsKeyLytec(apiKey))
            {
                return LytecConnector.GetResourcesList(apiKey);
            }
            else if (ProductType.IsKeyMedisoft(apiKey))
            {
                return MedisoftConnector.GetResourcesList(apiKey);
            }

            MSLSpecific.Logger.Error("Invalid Product");
            return null;
        }

        #endregion
    }
}
