package net.northking.cctp.element.datetime.enums;

import com.alibaba.fastjson.JSON;
import net.northking.cctp.element.core.type.EnumClass;

import java.util.*;

/**
 * TypeConversionEnum
 *
 * @author fengxiang.zhang
 * @since 1.0
 */
public enum TypeConversionOperateEnum implements EnumClass {
    StringOperate("字符串格式日期做加减操作", "0"),
    TimeStampOperate("时间戳格式日期做加减操作", "1"),
    ;

    private String key;
    private String value;

    TypeConversionOperateEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public static TypeConversionOperateEnum from(String value) {
        for (TypeConversionOperateEnum item : TypeConversionOperateEnum.values()) {
            if (item.value.equals(value)) {
                return item;
            }
        }
        throw new IllegalArgumentException("未知的转换类型:" + value);
    }

    @Override
    public String getEnumData() {
        List<Map<String, Object>> result = new ArrayList<>();
        for (TypeConversionOperateEnum item : EnumSet.allOf(TypeConversionOperateEnum.class)) {
            Map<String, Object> one = new HashMap(1);
            one.put("label", item.key);
            one.put("value", item.value);
            result.add(one);
        }
        return JSON.toJSONString(result);
    }
}
