package com.yimeng.okr.enums;

import lombok.Getter;

import java.time.LocalDate;

@Getter
public enum PeriodType {
    WEEKLY("单周", 6, 0),
    BI_WEEKLY("双周", 13, 0),
    MONTHLY("单月", 0, 1),
    BI_MONTHLY("双月", 0, 2),
    QUARTERLY("季度", 0, 3);

    private final String label;
    private final int days;
    private final int months;

    PeriodType(String label, int days, int months) {
        this.label = label;
        this.days = days;
        this.months = months;
    }

    public LocalDate calculateEndDate(LocalDate startDate) {
        if (months > 0) {
            LocalDate next = startDate.plusMonths(months);
            if (next.getDayOfMonth() < startDate.getDayOfMonth()) {
                return next;
            }
            return next.minusDays(1);
        }
        return startDate.plusDays(days);
    }
}
