/***********************************************************************************************************
 * Name         : CustomPathHelper
 * Purpose      : Helper methods for customPath LWC
 **********************************************************************************************************/

public class CustomPathHelper {
    public static String ACTIVE_SLDS_PATH_ITEM_CLASS = 'slds-path__item slds-is-active';
    public static String INCOMPLETE_SLDS_PATH_ITEM_CLASS = 'slds-path__item slds-is-incomplete';
    public static String COMPLETE_SLDS_PATH_ITEM_CLASS = 'slds-path__item slds-is-complete';

    /**
     * @description Returns a list of Stages and their respective SLDS class according to
     *  past, current and future Stages
     * @param String    current Opp's Stage
     * @param String    current Opp's Record Type Dev Name
     * @return List<PathData>   list of wrappers
     */
    @AuraEnabled(cacheable=true)
    public static List<PathData> getData(String currentStage, String recordTypeDevName) {
        Boolean currentValueMatched = false;
        List<PathData> pathDataList = new List<PathData>();
        List<String> stages = getStagesByRecordTypeName(recordTypeDevName);

        for (String stage : stages) {
            PathData pathData = new PathData();
            pathData.label = stage;

            if (pathData.label == currentStage) {
                pathData.classValue = ACTIVE_SLDS_PATH_ITEM_CLASS;
                currentValueMatched = true;
            } else if (currentValueMatched) {
                pathData.classValue = INCOMPLETE_SLDS_PATH_ITEM_CLASS;
            } else {
                pathData.classValue = COMPLETE_SLDS_PATH_ITEM_CLASS;
            }

            pathDataList.add(pathData);
        }
        return pathDataList;
    }

    /**
     * @description Returns a list of Stages based on the Opp's Record Type
     * @param String        current Opp's Record Type Dev Name
     * @return List<String> list of Stages
     */
    private static List<String> getStagesByRecordTypeName(String recordTypeDevName) {
        List<String> stages = new List<String>();
        if (CA_Constants.OPP_RECORD_TYPES.contains(recordTypeDevName)) {
            stages = CA_Constants.OPPORTUNITY_STAGE_LIST;
        }
        return stages;
    }

    public class PathData {
        @AuraEnabled
        public String label;
        @AuraEnabled
        public String classValue;
    }
}