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

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import dev.sonpx.loyalty.mcp.enums.EnumBase;
import java.util.Arrays;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum PeriodicType implements EnumBase {
    DAY("D"),
    WEEK("W"),
    MONTH("M"),
    YEAR("Y");

    @JsonValue
    private final String code;

    @JsonCreator
    public static PeriodicType fromCode(String code) {
        return Arrays.stream(values())
                .filter(periodicType -> periodicType.getCode().equals(code))
                .findFirst()
                .orElse(null);
    }
}
