package cn.nianxx.thhotel.workflows.reservation.service.impl;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import cn.nianxx.thhotel.workflows.reservation.common.dto.ReservationTaskSnapshot;
import cn.nianxx.thhotel.workflows.reservation.common.enums.ReservationTaskStatus;
import cn.nianxx.thhotel.workflows.reservation.common.result.ReservationTaskAvailabilityResult;
import cn.nianxx.thhotel.workflows.reservation.repository.ReservationAiWorkflowRepository;
import java.util.List;
import org.junit.jupiter.api.Test;

class ReservationTaskAvailabilityResolverTest {

    @Test
    void shouldReturnReadOnlyForNonQueueTaskWithoutQueryingPreviousTasks() {
        ReservationAiWorkflowRepository workflowRepository = mock(ReservationAiWorkflowRepository.class);
        when(workflowRepository.findQueueTasksBefore(anyString(), anyLong(), nullable(Integer.class)))
                .thenReturn(List.of());
        ReservationTaskAvailabilityResolver resolver = new ReservationTaskAvailabilityResolver(workflowRepository);
        ReservationTaskSnapshot nonQueueTask = task(false, null, ReservationTaskStatus.PENDING_CONFIRM.name());

        ReservationTaskAvailabilityResult result = resolver.calculateAvailability(nonQueueTask);

        assertThat(result.blocked()).isFalse();
        assertThat(result.readOnly()).isTrue();
        assertThat(result.editable()).isFalse();
        assertThat(result.confirmable()).isFalse();
        assertThat(result.executable()).isFalse();
        verify(workflowRepository, never()).findQueueTasksBefore(anyString(), anyLong(), nullable(Integer.class));
    }

    private ReservationTaskSnapshot task(Boolean queueParticipation, Integer executionOrder, String taskStatus) {
        return new ReservationTaskSnapshot(
                930000000000001001L,
                "HOTEL-TEST",
                930000000000001101L,
                930000000000001201L,
                930000000000001301L,
                "message_notification",
                "Message Notification",
                "MESSAGE_NOTIFICATION",
                "MESSAGE_NOTIFICATION",
                "message_notification",
                taskStatus,
                queueParticipation,
                executionOrder,
                null,
                null,
                null,
                false,
                null);
    }
}
