from __future__ import annotations

import calendar
from datetime import date

CONTRIBUTION_STATUSES = {
    "accepted_pending_payment",
    "active",
    "suspended_contribution",
    "resigned_end_of_year",
}


def date_in_year(source: date, year: int) -> date:
    return date(year, source.month, min(source.day, calendar.monthrange(year, source.month)[1]))


def relative_title(name: str, delta: int, occasion: str) -> str:
    if delta == 0:
        return f"{name} hat heute {occasion}"
    unit = "Tag" if abs(delta) == 1 else "Tagen"
    if delta > 0:
        return f"{name} hat in {delta} {unit} {occasion}"
    return f"{name} hatte vor {-delta} {unit} {occasion}"
