using System;
using System.Collections.Generic;

namespace MainShell.Process
{
    public static class WorkflowStepIdResolver
    {
        private static readonly IReadOnlyDictionary<string, string> AutoProductionEntryStepIdMap =
            new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { ProcessFlowName.SubstrateLoadFlow, WorkflowStepIds.AutoProduction.SubstrateLoadEntry },
                { ProcessFlowName.SubstratePositionFlow, WorkflowStepIds.AutoProduction.SubstratePositionEntry },
                { ProcessFlowName.SubstrateHeightMeasureFlow, WorkflowStepIds.AutoProduction.SubstrateHeightMeasureEntry },
                { ProcessFlowName.PreparationSignalFlow, WorkflowStepIds.AutoProduction.PreparationSignalEntry },
                { ProcessFlowName.ChipPreparationSyncFlow, WorkflowStepIds.AutoProduction.ChipPreparationSyncEntry },
                { ProcessFlowName.PreTransferValidationFlow, WorkflowStepIds.AutoProduction.PreTransferValidationEntry },
                { ProcessFlowName.ChipStraighteningFlow, WorkflowStepIds.AutoProduction.ChipStraighteningEntry },
                { ProcessFlowName.DiePositionFlow, WorkflowStepIds.AutoProduction.DiePositionEntry },
                { ProcessFlowName.DieTransferFlow, WorkflowStepIds.AutoProduction.DieTransferEntry },
                { ProcessFlowName.DieRecheckFlow, WorkflowStepIds.AutoProduction.DieRecheckEntry },
                { ProcessFlowName.ChipUnloadFlow, WorkflowStepIds.AutoProduction.ChipUnloadEntry },
                { ProcessFlowName.SubstrateUnloadFlow, WorkflowStepIds.AutoProduction.SubstrateUnloadEntry }
            };

        public static string GetAutoProductionEntryStepId(string flowName)
        {
            if (TryGetAutoProductionEntryStepId(flowName, out var stepId))
            {
                return stepId;
            }

            return WorkflowStepIds.AutoProduction.SubstrateLoadEntry;
        }

        public static bool TryGetAutoProductionEntryStepId(string flowName, out string stepId)
        {
            if (string.IsNullOrWhiteSpace(flowName))
            {
                stepId = null;
                return false;
            }

            return AutoProductionEntryStepIdMap.TryGetValue(flowName, out stepId);
        }
    }
}
