package com.brilliance.isc.common.trndoc.vo;

import java.util.Arrays;
import java.util.Optional;

public enum CorTypeWfmEnum {
    SWT_103("wfmAdd_Qin"),

    SWT_202("wfmAdd_Qin"),

    SWT_ALL("wfmAdd_Swift"),

    ELC_ALL("wfmAdd_ELC"),

    RTG_ALL("wfmAdd_RTGS_Plus"),

    TAR_ALL("wfmAdd_Target"),

    TLX_ALL("wfmAdd_Telex"),

    FAX_ALL("wfmAdd_FAX"),

    EML_ALL("wfmAdd_email"),

    EMA_ALL("wfmAdd_email"),

    LET_CMT("wfmAdd_CMT100"),

    LET_HVP("wfmAdd_HVPS"),

    LET_HVQ("wfmAdd_HVPS"),

    LET_CIU("wfmAdd_CIPS"),

    LET_CIV("wfmAdd_CIPS"),

    INT_CMT("wfmAdd_CMT100"),

    INT_HVP("wfmAdd_HVPS"),

    INT_HVQ("wfmAdd_HVPS"),

    INT_CIU("wfmAdd_CIPS"),

    INT_CIV("wfmAdd_CIPS"),

    TCO_ALL("wfmAdd_Tradeconnect"),

    TCA_ALL("wfmAdd_Tradeconnect"),

    ERX_YPTGNZ("wfmAdd_YPTGNZ"),

    FMT_ALL("wfmAdd_FMT"),

    ERX_ERX("wfmAdd_ERX");

    String wfm;

    CorTypeWfmEnum(String wfm) {
        this.wfm = wfm;
    }

    public String getWfm() {
        return wfm;
    }

    public static String getWfmByCorTypeAndMsgType(String corType, String msgType) {
        if (corType != null) {
            corType = corType.toUpperCase();
        }
        if (msgType != null) {
            msgType = msgType.toUpperCase();
        }
        String finalCorType = corType;
        String finalMsgType = msgType;
        Optional<CorTypeWfmEnum> corTypeWfmEnumOptional = Arrays.stream(CorTypeWfmEnum.values())
                .filter(corTypeWfmEnum -> (finalCorType + "_" + finalMsgType).equals(corTypeWfmEnum.name())).findFirst();
        if (!corTypeWfmEnumOptional.isPresent()) {
            corTypeWfmEnumOptional = Arrays.stream(CorTypeWfmEnum.values())
                    .filter(corTypeWfmEnum -> (finalCorType + "_ALL").equals(corTypeWfmEnum.name())).findFirst();
        }
        if (corTypeWfmEnumOptional.isPresent()) {
            return corTypeWfmEnumOptional.get().getWfm();
        } else {
            return "WfmAdd_" + corType;
        }
    }
}
