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

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

@Getter
@RequiredArgsConstructor
public enum RepRunSchedule {
    DAILY("D"),
    MONTHLY("M"),
    ANNUALLY("A"),
    N_DAYS_AFTER_AOD("NDAA"),
    N_MONTHS_AFTER_AOD("NMAA"),
    STATEMENT_CYCLE("SCD");

    @JsonValue
    private final String code;

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

    public static boolean isRepRunSchedule(RepRunSchedule schedule) {
        return List.of(DAILY, MONTHLY, ANNUALLY, N_DAYS_AFTER_AOD, N_MONTHS_AFTER_AOD, STATEMENT_CYCLE)
                .contains(schedule);
    }
}
