use super::{
    clamp_date_time_span,
    test::{date_time_span, datetime_utc},
    DateTimeSpan,
};

#[test]
fn should_not_clamp_if_start_and_end_are_none() {
    let in_span = date_time_span("2025-11-01", "12:02:00", "2025-11-10", "14:00:00");

    let out_span = clamp_date_time_span(None, None, in_span.clone());

    assert_eq!(in_span, out_span);
}

#[test]
fn should_not_clamp_if_start_and_end_are_contained() {
    let start = datetime_utc("2025-11-01", "12:02:00");
    let end = datetime_utc("2025-11-10", "14:00:00");
    let in_span = DateTimeSpan { start, end };
    let min_date = datetime_utc("2025-11-01", "11:00:00");
    let max_date = datetime_utc("2025-11-10", "15:00:00");

    let out_span = clamp_date_time_span(Some(min_date), Some(max_date), in_span.clone());

    assert_eq!(in_span, out_span);
}

#[test]
fn should_clamp_if_span_start_earlier() {
    let start = datetime_utc("2025-11-01", "12:02:00");
    let end = datetime_utc("2025-11-10", "14:00:00");
    let in_span = DateTimeSpan { start, end };
    let min_date = datetime_utc("2025-11-02", "00:00:00");
    let max_date = datetime_utc("2025-11-10", "23:00:00");

    let out_span = clamp_date_time_span(Some(min_date), Some(max_date), in_span);

    assert_eq!(out_span.start, min_date);
    assert_eq!(out_span.end, end);
}

#[test]
fn should_clamp_if_end_later() {
    let start = datetime_utc("2025-11-01", "12:02:00");
    let end = datetime_utc("2025-11-10", "14:00:00");
    let in_span = DateTimeSpan { start, end };
    let min_date = datetime_utc("2025-11-01", "00:00:00");
    let max_date = datetime_utc("2025-11-09", "23:00:00");

    let out_span = clamp_date_time_span(Some(min_date), Some(max_date), in_span);

    assert_eq!(out_span.start, start);
    assert_eq!(out_span.end, max_date);
}
