using Eaf.Management.ConfigurationData.CellAutomation;
using Ifx.Eaf.EquipmentConnector.File.Configuration;
using System.Collections.Generic;

namespace Shared;

public static class Mapper
{

    internal static Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration Map(FileConnectorConfiguration configuration)
    {
        Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration result = new()
        {
            AlternateTargetFolder = configuration.AlternateTargetFolder,
            ConnectionRetryInterval = configuration.ConnectionRetryInterval,
            ConnectionSettings = new List<Adaptation.Ifx.Eaf.Common.Configuration.ConnectionSetting>(),
            CopySourceFolderStructure = configuration.CopySourceFolderStructure,
            DefaultPlaceHolderValue = configuration.DefaultPlaceHolderValue,
            //DeleteAbandonedEmptySourceSubFolders = configuration.DeleteAbandonedEmptySourceSubFolders,
            DeleteEmptySourceSubFolders = configuration.DeleteEmptySourceSubFolders,
            ErrorPostProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PostProcessingModeEnum)configuration.ErrorPostProcessingMode,
            ErrorTargetFileLocation = configuration.ErrorTargetFileLocation,
            ErrorTargetFileName = configuration.ErrorTargetFileName,
            FileAgeFilterMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.FileAgeFilterEnum)configuration.FileAgeFilterMode,
            FileAgeThreshold = configuration.FileAgeThreshold,
            //FileHandlers = configuration.FileHandlers,
            FileHandleTimeout = (long)configuration.FileHandleTimeout,
            FileHandleWaitTime = configuration.FileHandleWaitTime,
            FileScanningIntervalInSeconds = configuration.FileScanningIntervalInSeconds,
            FileScanningOption = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.FileScanningOptionEnum)configuration.FileScanningOption,
            FolderAgeCheckIndividualSubFolders = configuration.FolderAgeCheckIndividualSubFolders,
            FolderAgeThreshold = configuration.FolderAgeThreshold,
            //FolderOperationsSubFolderLevel = configuration.FolderOperationsSubFolderLevel,
            IdleEventWaitTimeInSeconds = (long)configuration.IdleEventWaitTimeInSeconds,
            IfFileExistAction = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.IfFileExistEnum)configuration.IfFileExistAction,
            IfPostProcessingFailsAction = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.IfPostProcessingFailsEnum)configuration.IfPostProcessingFailsAction,
            IncludeSubDirectories = configuration.IncludeSubDirectories,
            PostProcessingRetries = configuration.PostProcessingRetries,
            PreProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PreProcessingModeEnum)configuration.PreProcessingMode,
            PostProcessingMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.PostProcessingModeEnum)configuration.PostProcessingMode,
            SourceDirectoryCloaking = configuration.SourceDirectoryCloaking,
            SourceFileFilter = configuration.SourceFileFilter,
            SourceFileFilters = configuration.SourceFileFilters,
            SourceFileLocation = configuration.SourceFileLocation,
            TargetFileLocation = configuration.TargetFileLocation,
            TargetFileName = configuration.TargetFileName,
            TriggerOnChanged = configuration.TriggerOnChanged,
            TriggerOnCreated = configuration.TriggerOnCreated,
            UseZip64Mode = configuration.UseZip64Mode,
            ZipErrorTargetFileName = configuration.ZipErrorTargetFileName,
            ZipFileAmount = configuration.ZipFileAmount,
            ZipFileSubFolderLevel = configuration.ZipFileSubFolderLevel,
            ZipFileTime = configuration.ZipFileTime,
            ZipMode = (Adaptation.Ifx.Eaf.EquipmentConnector.File.Configuration.FileConnectorConfiguration.ZipModeEnum)configuration.ZipMode,
            ZipTargetFileName = configuration.ZipTargetFileName,
        };
        foreach (Ifx.Eaf.Common.Configuration.ConnectionSetting connectionSetting in configuration.ConnectionSettings)
            result.ConnectionSettings.Add(new Adaptation.Ifx.Eaf.Common.Configuration.ConnectionSetting(connectionSetting.Name, connectionSetting.Value));
        return result;
    }

    internal static IList<Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition> Map(IList<ModelObjectParameterDefinition> configuredParameters)
    {
        List<Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition> results = new();
        Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterType modelObjectParameterType;
        for (int i = 0; i < configuredParameters.Count; i++)
        {
            modelObjectParameterType = (Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterType)configuredParameters[i].ValueType;
            results.Add(new Adaptation.Eaf.Management.ConfigurationData.CellAutomation.ModelObjectParameterDefinition() { Id = i, Name = configuredParameters[i].Name, Value = configuredParameters[i].Value, ValueType = modelObjectParameterType, EnumType = modelObjectParameterType.ToString() });
        }
        return results;
    }

}
