package org.jeecg.modules.demo.adsaccount.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Getter
@AllArgsConstructor
public enum TimezoneID {
    ASIA_SHANGHAI("Asia/Shanghai"),
    ASIA_HONG_KONG("Asia/Hong_Kong"),
    AMERICA_NEW_YORK("America/New_York"),
    AMERICA_LOS_ANGELES("America/Los_Angeles"),
    UNK("UNKNOWN");

    private static final Map<String, TimezoneID> MAP =
            Stream.of(TimezoneID.values())
                    .collect(Collectors.toMap(TimezoneID::getId, Function.identity()));

    @JsonCreator
    public static TimezoneID valueOfId(String id) {
        return MAP.getOrDefault(id, UNK);
    }

    @JsonValue
    public String getId() {
        return id;
    }

    private String id;
}
