
package dev.sonpx.loyalty.mcp.reward.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * Created by SonPhung on Friday, 10-Nov-2023
 * This sets the cap on the sum of Result from the formulas set up in Rule.
 * If the Result from Rule exceeds this cap, then this cap is used as the Result.
 */
@Getter
@RequiredArgsConstructor
public enum AwardLimitType {
    NO_MORE_THAN("NM"),
    AT_LEAST("AL");

    @JsonValue
    private final String code;

    @JsonCreator
    public static AwardLimitType fromCode(String code) {
        return Arrays.stream(values())
                .filter(e -> e.code.equalsIgnoreCase(code))
                .findFirst()
                .orElse(null);
    }
}
