
package dev.sonpx.loyalty.mcp.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;

/**
 * Created by SonPhung on Monday, 20-Jul-2026
 * {@link #LAST_7_DAYS},
 * {@link #LAST_30_DAYS},
 * {@link #LAST_3_MONTHS},
 * {@link #LAST_6_MONTHS}
 */
@Getter
@RequiredArgsConstructor
public enum StatisticPeriod {
    TODAY("TODAY"),
    LAST_7_DAYS("L7D"),
    LAST_30_DAYS("L30D"),
    LAST_3_MONTHS("L3M"),
    LAST_6_MONTHS("L6M");

    @JsonValue
    private final String code;

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

    public boolean isAny(StatisticPeriod... periods) {
        return List.of(periods).contains(this);
    }
}
