package org.raddatz.familienarchiv.dashboard;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.raddatz.familienarchiv.document.DocumentService;
import org.raddatz.familienarchiv.dashboard.StatsDTO;
import org.raddatz.familienarchiv.geschichte.GeschichteService;
import org.raddatz.familienarchiv.person.PersonService;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class StatsServiceTest {

    @Mock PersonService personService;
    @Mock DocumentService documentService;
    @Mock GeschichteService geschichteService;
    @InjectMocks StatsService statsService;

    @Test
    void getStats_returnsCountsFromServices() {
        when(personService.count()).thenReturn(4L);
        when(documentService.count()).thenReturn(12L);

        StatsDTO stats = statsService.getStats();

        assertThat(stats.totalPersons()).isEqualTo(4L);
        assertThat(stats.totalDocuments()).isEqualTo(12L);
    }

    @Test
    void getStats_includes_totalStories() {
        when(personService.count()).thenReturn(3L);
        when(documentService.count()).thenReturn(7L);
        when(geschichteService.countPublished()).thenReturn(5L);

        StatsDTO stats = statsService.getStats();

        assertThat(stats.totalStories()).isEqualTo(5L);
    }

    @Test
    void getStats_returnsZero_whenNoEntities() {
        when(personService.count()).thenReturn(0L);
        when(documentService.count()).thenReturn(0L);

        StatsDTO stats = statsService.getStats();

        assertThat(stats.totalPersons()).isZero();
        assertThat(stats.totalDocuments()).isZero();
    }
}
