package com.oqpo.api.enums;

import com.oqpo.api.exception.GlobalException;
import lombok.Getter;
import lombok.Setter;

public enum WeightUnit {

    KG("10", "kg"), //
    G("20", "g"), //
    MG("30", "mg"), //
    TON("40", "ton"), //
    ;

    WeightUnit(String cd, String nm) {
        this.cd = cd;
        this.name = nm;
    }

    @Getter
    @Setter
    private String cd;

    @Getter
    @Setter
    private String name;

    public static String getCd(String nname) {
        WeightUnit[] values = WeightUnit.values();
        for (WeightUnit icd : values) {
            if (icd.name.equals(nname)) {
                return icd.cd;
            }
        }
        return nname;
    }

    public static String getName(String ccd) {
        WeightUnit[] values = WeightUnit.values();
        for (WeightUnit icd : values) {
            if (icd.cd.equals(ccd)) {
                return icd.name;
            }
        }
        return ccd;
    }

}
