
package dev.sonpx.loyalty.mcp.enums;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Arrays;
import java.util.Date;
import java.util.Optional;
import lombok.Getter;

@Getter
public enum JobParamDataType {
    STRING(String.class),
    LONG(Long.class),
    INTEGER(Integer.class),
    DOUBLE(Double.class),
    FLOAT(Float.class),
    DATE(Date.class),
    LOCAL_DATE(LocalDate.class), // yyyy-MM-dd
    LOCAL_TIME(LocalTime.class),
    LOCAL_DATE_TIME(LocalDateTime.class); // yyyy-MM-dd'T'HH:mm:ss

    private final Class<?> type;

    JobParamDataType(Class<?> type) {
        this.type = type;
    }

    public boolean supports(Object value) {
        return type.isInstance(value);
    }

    public static Optional<JobParamDataType> resolveType(Object value) {
        if (value == null) return Optional.empty();
        return Arrays.stream(values()).filter(t -> t.supports(value)).findFirst();
    }
}
