
package dev.sonpx.loyalty.mcp.enums;

import java.util.Arrays;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * Created by SonPhung on Monday, 20-Jul-2026
 */
@Getter
@RequiredArgsConstructor
public enum DerivedType {
    STRING("STRING", AttributeDataType.STRING),
    INT("INT", AttributeDataType.NUMBER),
    DECIMAL("DECIMAL", AttributeDataType.NUMBER),
    DATE("DATE", AttributeDataType.DATE),
    TIME("TIME", AttributeDataType.TIME),
    BOOLEAN("BOOLEAN", AttributeDataType.BOOLEAN),
    SEGMENT("SEGMENT", null),
    AUDIENCE("AUDIENCE", null);

    private final String code;

    private final AttributeDataType baseType;

    public static DerivedType fromCode(String code) {
        return Arrays.stream(DerivedType.values())
                .filter(o -> code.equals(o.getCode()))
                .findFirst()
                .orElse(null);
    }

    public static DerivedType fromBaseType(AttributeDataType baseType) {
        return Arrays.stream(DerivedType.values())
                .filter(o -> baseType.equals(o.getBaseType()))
                .findFirst()
                .orElse(null);
    }

    public static boolean isAudienceType(String code) {
        return DerivedType.AUDIENCE.code.equalsIgnoreCase(code) || DerivedType.SEGMENT.code.equalsIgnoreCase(code);
    }
}
