package com.eactive.eai.rms.data.entity.onl.apim.portalinquiry;

import com.eactive.apim.portal.qna.entity.InquiryComment;
import com.eactive.eai.rms.data.jpa.AbstractEMSDataSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(transactionManager = "transactionManagerForEMS")
public class PortalInquiryCommentService extends AbstractEMSDataSerivce<InquiryComment, String, PortalInquiryCommentRepository> {

    // AbstractEMSDataSerivce의 repository 필드가 BaseRepository<T,I>로 고정되어
    // 커스텀 메서드를 호출할 수 없으므로 별도 필드로 직접 주입
    @Autowired
    private PortalInquiryCommentRepository inquiryCommentRepository;

    public long countByInquiryId(String inquiryId) {
        return inquiryCommentRepository.countByInquiry_Id(inquiryId);
    }

    public long countActiveByInquiryId(String inquiryId) {
        return inquiryCommentRepository.countByInquiry_IdAndDelYn(inquiryId, "N");
    }

    public List<InquiryComment> findByInquiryId(String inquiryId) {
        return inquiryCommentRepository.findByInquiry_IdAndDelYnOrderByCreatedDateAsc(inquiryId, "N");
    }
}
