package com.hs.api.model.respmodel;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class EnumBean implements Serializable {
    private static final String ENUM_CLASS = "java.lang.Enum";
    private int id;
    private String name;
    private String value;

    public static List<EnumBean> enumToBeanList(Class clz) throws Throwable {
        if(!ENUM_CLASS.equalsIgnoreCase(clz.getSuperclass().getName())){
            throw new IllegalArgumentException(
                    "The argument [ " + clz.getName() + " ] can not be asssigned by " + "java.lang.Enum");
        }else{
            ArrayList list = new ArrayList();
            EnumBean bean = null;
            Enum[] enums = null;
            String value = null;
            Method m = clz.getDeclaredMethod("values",(Class[])null);
            enums = (Enum[])((Enum[])m.invoke((Object)null,(Object[])null));
            Enum[] arg5 = enums;
            int arg6 = enums.length;

            for(int arg7 = 0;arg7 < arg6;++arg7){
                Enum e = arg5[arg7];
                value = Enum.valueOf(clz,e.name()).toString();
                bean = new EnumBean();
                bean.setName(e.name());
                if(value.contains(":")){
                    bean.setId(Integer.parseInt(value.substring(0,value.indexOf(":"))));
                    bean.setValue(value.substring(value.indexOf(":") + 1));
                }else{
                    bean.setId(e.ordinal());
                    bean.setValue(e.name());
                }

                list.add(bean);
            }

            return list;
        }
    }

    public int getId() {
        return this.id;
    }

    private void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    private void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        return this.value;
    }

    private void setValue(String value) {
        this.value = value;
    }
}
