package com.pandoli365.bibimbap.jam;

import com.pandoli365.bibimbap.data.JamData;
import org.junit.jupiter.api.Test;

import java.time.OffsetDateTime;

import static org.assertj.core.api.Assertions.assertThat;

class JamEvalWindowTest {

    private static final OffsetDateTime BASE = OffsetDateTime.parse("2026-06-24T12:00:00+09:00");
    private static final OffsetDateTime START = BASE.minusHours(1);
    private static final OffsetDateTime END = BASE.plusHours(1);

    private static JamData jam(String status, OffsetDateTime start, OffsetDateTime end) {
        JamData jam = new JamData();
        jam.setStatus(status);
        jam.setEvalStartAt(start);
        jam.setEvalEndAt(end);
        return jam;
    }

    @Test
    void openWhenEvalAndWithinWindow() {
        assertThat(JamEvalWindow.isOpen(jam("EVAL", START, END), BASE)).isTrue();
    }

    @Test
    void openAtStartBoundary() {
        assertThat(JamEvalWindow.isOpen(jam("EVAL", START, END), START)).isTrue();
    }

    @Test
    void openAtEndBoundary() {
        assertThat(JamEvalWindow.isOpen(jam("EVAL", START, END), END)).isTrue();
    }

    @Test
    void closedWhenBeforeStart() {
        assertThat(JamEvalWindow.isOpen(jam("EVAL", START, END), START.minusSeconds(1))).isFalse();
    }

    @Test
    void closedWhenAfterEnd() {
        assertThat(JamEvalWindow.isOpen(jam("EVAL", START, END), END.plusSeconds(1))).isFalse();
    }

    @Test
    void closedWhenStatusNotEval() {
        assertThat(JamEvalWindow.isOpen(jam("RECRUIT", START, END), BASE)).isFalse();
    }

    @Test
    void closedWhenEvalStartNull() {
        assertThat(JamEvalWindow.isOpen(jam("EVAL", null, END), BASE)).isFalse();
    }

    @Test
    void closedWhenEvalEndNull() {
        assertThat(JamEvalWindow.isOpen(jam("EVAL", START, null), BASE)).isFalse();
    }

    @Test
    void closedWhenJamNull() {
        assertThat(JamEvalWindow.isOpen(null, BASE)).isFalse();
    }

    @Test
    void closedWhenNowNull() {
        assertThat(JamEvalWindow.isOpen(jam("EVAL", START, END), null)).isFalse();
    }
}
