package com.capgemini.reports.periodicity;

import com.capgemini.reports.database.javabean.enumeration.SchedulingEnum;
import com.capgemini.reports.database.manager.MngSchedulingCriteriaVal.SchedulingCriteriaValue;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * Represents an periodicity that occurs on a specific day, each month.
 */
@Getter
public class DayInMonth implements SchedulingPeriod {

    private final Integer dayInMonth;

    /**
     * Builds a instance.
     *
     * @param dayInMonth the day in the month. [1-31]
     */
    public DayInMonth(final int dayInMonth) {
        this.dayInMonth = dayInMonth;
    }

    @Override
    public SchedulingEnum getPeriodicity() {
        return SchedulingEnum.DAY_IN_MONTH_VALUE;
    }

    @Override
    public <T> T accept(final PeriodVisitor<T> visitor) {
        return visitor.visit(this);
    }

    @Override
    public List<SchedulingCriteriaValue> asCriteriaValues() {
        List<SchedulingCriteriaValue> list = new ArrayList<>(2);
        list.add(new SchedulingCriteriaValue(SchedulingEnum.PERIOD, SchedulingEnum.DAY_IN_MONTH_VALUE.getCriteriaName()));
        list.add(new SchedulingCriteriaValue(SchedulingEnum.DAY_IN_MONTH_VALUE, String.valueOf(dayInMonth)));
        return list;
    }

}
