package com.infoepoch.pms.agent.platform.chat.domain;

import com.infoepoch.pms.agent.platform.chatbot.domain.Chatbot;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class SessionTest {

    @Test
    void shouldInitializeActiveThreadWhenSessionIsCreated() {
        Session session = new Session("user-1", chatbot());

        assertEquals(session.getId(), session.getActiveThreadId());
        assertFalse(session.isContextResetPending());
    }

    @Test
    void shouldMarkAndClearContextResetState() {
        Session session = Session.restore(
                "session-1",
                "user-1",
                chatbot(),
                Session.STATUS_ACTIVE,
                null,
                "session-1",
                false,
                LocalDateTime.now(),
                LocalDateTime.now()
        );

        session.markContextResetPending();
        assertTrue(session.isContextResetPending());

        session.clearContextResetPending();
        assertFalse(session.isContextResetPending());

        session.activateNextThread("session-1_thread_2");
        assertEquals("session-1_thread_2", session.getActiveThreadId());
        assertFalse(session.isContextResetPending());
    }

    private Chatbot chatbot() {
        LocalDateTime now = LocalDateTime.now();
        return Chatbot.restore(
                "chatbot-1",
                "客服助手",
                "desc",
                null,
                null,
                List.of(),
                20,
                true,
                now,
                now,
                Set.of()
        );
    }
}
