"""Tests for app/utils/date_utils.py — 100% branch coverage required."""
from datetime import date
import pytest
from app.utils.date_utils import add_months, month_start, month_end


class TestAddMonths:
    def test_normal_addition(self):
        assert add_months(date(2026, 5, 15), 1) == date(2026, 6, 15)

    def test_month_end_rollover_jan_to_feb(self):
        """Jan 31 + 1 month = Feb 28 (not Mar 3)."""
        assert add_months(date(2026, 1, 31), 1) == date(2026, 2, 28)

    def test_month_end_rollover_leap_year(self):
        """Jan 31 + 1 month in leap year = Feb 29."""
        assert add_months(date(2024, 1, 31), 1) == date(2024, 2, 29)

    def test_negative_months(self):
        assert add_months(date(2026, 3, 31), -1) == date(2026, 2, 28)

    def test_twelve_months(self):
        assert add_months(date(2026, 5, 15), 12) == date(2027, 5, 15)

    def test_zero_months(self):
        assert add_months(date(2026, 5, 15), 0) == date(2026, 5, 15)


class TestMonthStart:
    def test_mid_month(self):
        assert month_start(date(2026, 5, 15)) == date(2026, 5, 1)

    def test_already_first(self):
        assert month_start(date(2026, 5, 1)) == date(2026, 5, 1)

    def test_last_day(self):
        assert month_start(date(2026, 5, 31)) == date(2026, 5, 1)


class TestMonthEnd:
    def test_february_non_leap(self):
        assert month_end(date(2026, 2, 1)) == date(2026, 2, 28)

    def test_february_leap_year(self):
        assert month_end(date(2024, 2, 1)) == date(2024, 2, 29)

    def test_thirty_day_month(self):
        assert month_end(date(2026, 4, 1)) == date(2026, 4, 30)

    def test_thirty_one_day_month(self):
        assert month_end(date(2026, 5, 1)) == date(2026, 5, 31)

    def test_already_last_day(self):
        assert month_end(date(2026, 5, 31)) == date(2026, 5, 31)
