package com.kt.event.content.biz.service;

import com.kt.event.content.biz.domain.GeneratedImage;
import com.kt.event.content.biz.domain.ImageStyle;
import com.kt.event.content.biz.domain.Platform;
import com.kt.event.content.biz.dto.ImageInfo;
import com.kt.event.content.biz.usecase.in.GetImageListUseCase;
import com.kt.event.content.biz.usecase.out.ContentReader;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 이미지 목록 조회 서비스
 */
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class GetImageListService implements GetImageListUseCase {

    private final ContentReader contentReader;

    @Override
    public List<ImageInfo> execute(String eventId, ImageStyle style, Platform platform) {
        log.info("이미지 목록 조회: eventId={}, style={}, platform={}", eventId, style, platform);

        List<GeneratedImage> images = contentReader.findImagesByEventDraftId(eventId);

        // 필터링 적용
        return images.stream()
                .filter(image -> style == null || image.getStyle() == style)
                .filter(image -> platform == null || image.getPlatform() == platform)
                .map(ImageInfo::from)
                .collect(Collectors.toList());
    }
}
