
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;

/**
 * Created by SonPhung on Wednesday, 20-Dec-2023
 */
@Getter
@RequiredArgsConstructor
public enum CounterPeriod {
    AOD_ANNIVERSARY("AA"),
    DAY_COUNTER("DC"),
    DAYS_FROM_AOD("DFA"),
    DAYS_FROM_COD("DFC"),
    FIXED_DATE("FD"),
    HALF_YEAR("HY"),
    MONTHS_FROM_AOD("MFA"),
    MONTHS_COUNTER("MC"),
    NON_EXPIRE("NE"),
    QUARTER_COUNTER("QC"),
    QUARTER_FROM_AOD("QFA"),
    WEEK_COUNTER("WC"),
    YEAR_COUNTER("YC"),
    STATEMENT_CYCLE("SC");

    @JsonValue
    private final String code;

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

}
