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

import com.kt.event.common.exception.BusinessException;
import com.kt.event.common.exception.ErrorCode;
import com.kt.event.content.biz.domain.Content;
import com.kt.event.content.biz.dto.ContentInfo;
import com.kt.event.content.biz.usecase.in.GetEventContentUseCase;
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;

/**
 * 이벤트 콘텐츠 조회 서비스
 */
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class GetEventContentService implements GetEventContentUseCase {

    private final ContentReader contentReader;

    @Override
    public ContentInfo execute(Long eventDraftId) {
        Content content = contentReader.findByEventDraftIdWithImages(eventDraftId)
                .orElseThrow(() -> new BusinessException(ErrorCode.COMMON_001, "콘텐츠를 찾을 수 없습니다"));

        return ContentInfo.from(content);
    }
}
