"""Tests para next_cron_time."""

from datetime import datetime

from next_cron_time import next_cron_time
from parse_cron_expr import parse_cron_expr


def test_0_star_desde_30_retorna_proxima_hora_en_punto():
    """0 * * * * desde :30 retorna la proxima hora en punto"""
    sched = parse_cron_expr("0 * * * *")
    after = datetime(2024, 1, 15, 14, 30)
    nxt = next_cron_time(sched, after)
    assert nxt == datetime(2024, 1, 15, 15, 0)


def test_0_9_weekdays_desde_viernes_retorna_proximo_lunes():
    """0 9 * * 1-5 desde viernes retorna proximo lunes a las 9"""
    sched = parse_cron_expr("0 9 * * 1-5")
    # 2024-01-19 es viernes
    friday = datetime(2024, 1, 19, 10, 0)
    nxt = next_cron_time(sched, friday)
    # 2024-01-22 es lunes
    assert nxt == datetime(2024, 1, 22, 9, 0)


def test_schedule_imposible_retorna_none():
    """schedule imposible retorna None"""
    # 31 de febrero no existe — schedule nunca se cumple en 366 dias
    sched = parse_cron_expr("0 0 31 2 *")
    after = datetime(2024, 1, 1)
    nxt = next_cron_time(sched, after)
    assert nxt is None


def test_paso_15_desde_05_retorna_15():
    """paso */15 desde :05 retorna :15"""
    sched = parse_cron_expr("*/15 * * * *")
    after = datetime(2024, 3, 10, 8, 5)
    nxt = next_cron_time(sched, after)
    assert nxt == datetime(2024, 3, 10, 8, 15)
