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

namespace Edge.Core.Processor.Dispatcher
{
    public interface IProcessorLoader
    {
        /// <summary>
        /// Create (Instantiate) all Processor instances based on underlying configs.
        /// </summary>
        /// <returns></returns>
        IEnumerable<ProcessorInstanceOperatingResult> CreateAll();

        /// <summary>
        /// Create (Instantiate) a single Processor instance based on config name.
        /// </summary>
        /// <param name="configName"></param>
        /// <returns></returns>
        IProcessor Create(string configName);
    }

    public interface IProcessorMetaConfigAccessor
    {
        /// <summary>
        /// Get all meta configs from uderlying persist ProcessorMetaConfigs.
        /// </summary>
        /// <returns>each source Endpoint Type could have multiple configs</returns>
        Task<IEnumerable<ProcessorMetaConfig>> GetMetaConfigAsync();
        /// <summary>
        /// Get meta configs from uderlying persist ProcessorMetaConfigs with searching condition of SourceEndpointFullTypeStr.
        /// </summary>
        /// <param name="sourceEndpointFullTypeStr">sample like-> Applications.FDC.FdcServerHostApp, FdcServerHost, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</param>
        /// <returns>each source Endpoint Type could have multiple configs</returns>
        Task<IEnumerable<ProcessorMetaConfig>> GetMetaConfigAsync(string sourceEndpointFullTypeStr);

        ///// <summary>
        ///// Get meta configs from uderlying persist ProcessorMetaConfigs with searching condition of SourceEndpointFullTypeStr.
        ///// </summary>
        ///// <param name="metaConfigId"></param>
        ///// <returns></returns>
        //Task<ProcessorMetaConfig> GetMetaConfigAsync(int metaConfigId);

        Task<ProcessorMetaConfig> UpsertMetaConfigAsync(ProcessorMetaConfig metaConfig);
        Task<bool> RemoveMetaConfigAsync(int metaConfigId);

        /// <summary>
        /// Used for internally(AppProcessor or DeviceHanlder?) to get the meta parts config for a processor.
        /// </summary>
        /// <param name="processor">instance of the processsor</param>
        /// <param name="metaPartsType"></param>
        /// <returns></returns>
        Task<ProcessorMetaPartsConfig> GetMetaPartsMetaConfigAsync(IProcessor processor,
            ProcessorMetaPartsTypeEnum metaPartsType);
        /// <summary>
        /// Used for internally(AppProcessor or DeviceHanlder?) to upsert the meta parts config for a processor.
        /// </summary>
        /// <param name="processor"></param>
        /// <param name="metaPartsType"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<ProcessorMetaPartsConfig> UpdateMetaPartsMetaConfigAsync(IProcessor processor,
            ProcessorMetaPartsTypeEnum metaPartsType, object[] parameters);
        /// <summary>
        /// Used for internally(AppProcessor or DeviceHanlder?) to remove the meta parts config for a processor.
        /// </summary>
        /// <param name="processorMetaPartsConfigId"></param>
        /// <returns></returns>
        Task<bool> RemoveMetaPartsMetaConfigAsync(IProcessor processor, int processorMetaPartsConfigId);
    }
}
