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.usecase.in.DeleteImageUseCase;
import com.kt.event.content.biz.usecase.out.ContentReader;
import com.kt.event.content.biz.usecase.out.ContentWriter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 이미지 삭제 서비스
 */
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional
public class DeleteImageService implements DeleteImageUseCase {

    private final ContentReader contentReader;
    private final ContentWriter contentWriter;

    @Override
    public void execute(Long imageId) {
        log.info("[DeleteImageService] 이미지 삭제 요청: imageId={}", imageId);

        // 이미지 존재 확인
        contentReader.findImageById(imageId)
                .orElseThrow(() -> new BusinessException(ErrorCode.COMMON_001, "이미지를 찾을 수 없습니다"));

        // 이미지 삭제
        contentWriter.deleteImageById(imageId);

        log.info("[DeleteImageService] 이미지 삭제 완료: imageId={}", imageId);
    }
}
