package com.yimeng.okr.enums;

import org.junit.jupiter.api.Test;

import java.time.LocalDate;

import static org.junit.jupiter.api.Assertions.*;

class PeriodTypeTest {

    @Test
    void weeklyEndsSixDaysLater() {
        // Monday start → Sunday end (6 days later, 7-day period inclusive)
        assertEquals(LocalDate.of(2026, 6, 7),
                PeriodType.WEEKLY.calculateEndDate(LocalDate.of(2026, 6, 1)));
    }

    @Test
    void biWeeklyEndsThirteenDaysLater() {
        // Monday start → Sunday of next week (13 days later, 14-day period inclusive)
        assertEquals(LocalDate.of(2026, 6, 14),
                PeriodType.BI_WEEKLY.calculateEndDate(LocalDate.of(2026, 6, 1)));
    }

    @Test
    void monthlyJun15toJul14() {
        // Natural month: 6.15 → 7.14
        assertEquals(LocalDate.of(2026, 7, 14),
                PeriodType.MONTHLY.calculateEndDate(LocalDate.of(2026, 6, 15)));
    }

    @Test
    void monthlyJan31toFeb28() {
        // End-of-month boundary: Jan 31 covers through the last day of February
        assertEquals(LocalDate.of(2026, 2, 28),
                PeriodType.MONTHLY.calculateEndDate(LocalDate.of(2026, 1, 31)));
    }

    @Test
    void monthlyMar31toApr30() {
        // March 31 → April 30
        assertEquals(LocalDate.of(2026, 4, 30),
                PeriodType.MONTHLY.calculateEndDate(LocalDate.of(2026, 3, 31)));
    }

    @Test
    void biMonthlyCorrect() {
        assertEquals(LocalDate.of(2026, 8, 14),
                PeriodType.BI_MONTHLY.calculateEndDate(LocalDate.of(2026, 6, 15)));
    }

    @Test
    void quarterlyCorrect() {
        assertEquals(LocalDate.of(2026, 9, 14),
                PeriodType.QUARTERLY.calculateEndDate(LocalDate.of(2026, 6, 15)));
    }
}
