package incheon.product.common.theme.service.impl;

import incheon.product.common.theme.mapper.CommonThemeMapper;
import incheon.product.common.theme.vo.ThemeCategoryVO;
import incheon.product.common.theme.vo.ThemeLayerVO;
import incheon.product.common.theme.vo.ThemeVO;
import org.junit.jupiter.api.DisplayName;
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 java.util.List;

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

/**
 * CommonThemeServiceImpl 단위 테스트.
 * 단순 위임 메서드의 Mapper 호출을 검증한다.
 */
@ExtendWith(MockitoExtension.class)
class CommonThemeServiceImplTest {

    @InjectMocks
    private CommonThemeServiceImpl commonThemeService;

    @Mock
    private CommonThemeMapper commonThemeMapper;

    @Test
    @DisplayName("getCategories는 mapper에 위임한다")
    void getCategories() {
        List<ThemeCategoryVO> expected = List.of(new ThemeCategoryVO());
        when(commonThemeMapper.selectCategories()).thenReturn(expected);

        List<ThemeCategoryVO> result = commonThemeService.getCategories();

        assertThat(result).isEqualTo(expected);
        verify(commonThemeMapper).selectCategories();
    }

    @Test
    @DisplayName("getThemes는 mapper에 위임한다")
    void getThemes() {
        List<ThemeVO> expected = List.of(new ThemeVO());
        when(commonThemeMapper.selectThemes()).thenReturn(expected);

        List<ThemeVO> result = commonThemeService.getThemes();

        assertThat(result).isEqualTo(expected);
        verify(commonThemeMapper).selectThemes();
    }

    @Test
    @DisplayName("getTheme은 mapper에 themeId를 전달한다")
    void getTheme() {
        ThemeVO expected = new ThemeVO();
        when(commonThemeMapper.selectThemeById("theme1")).thenReturn(expected);

        ThemeVO result = commonThemeService.getTheme("theme1");

        assertThat(result).isEqualTo(expected);
        verify(commonThemeMapper).selectThemeById("theme1");
    }

    @Test
    @DisplayName("getLayersByThemeId는 mapper에 themeId를 전달한다")
    void getLayersByThemeId() {
        List<ThemeLayerVO> expected = List.of(new ThemeLayerVO());
        when(commonThemeMapper.selectLayersByThemeId("t1")).thenReturn(expected);

        List<ThemeLayerVO> result = commonThemeService.getLayersByThemeId("t1");

        assertThat(result).isEqualTo(expected);
        verify(commonThemeMapper).selectLayersByThemeId("t1");
    }
}
