
package dev.sonpx.loyalty.mcp.enums;

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

@Getter
@RequiredArgsConstructor
public enum ExpiryPolicy {
    FIXED_DATE("FD"),
    NO_EXPIRY("NE"),
    ANNUAL_RECURRING_DATE("ARD"),
    N_MONTHS_FROM_MONTH_OF_EARNING("MF"),
    N_QUARTERS_FROM_QUARTER_OF_EARNING("QF"),
    N_YEARS_FROM_YEAR_OF_EARNING("YF"),
    SEMI_ANNUAL_OR_MID_AND_END_YEAR("SP"),
    ANNIVERSARY_OF_MEMBERSHIP("AOM");

    @JsonValue
    private final String code;

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