package com.unicorn.hgzero.meeting.biz.service;

import com.unicorn.hgzero.meeting.biz.domain.AgendaSection;
import com.unicorn.hgzero.meeting.biz.usecase.out.AgendaSectionReader;
import com.unicorn.hgzero.meeting.biz.usecase.out.AgendaSectionWriter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 안건별 회의록 섹션 서비스
 */
@Service
@RequiredArgsConstructor
@Slf4j
@Transactional(readOnly = true)
public class AgendaSectionService {

    private final AgendaSectionReader agendaSectionReader;
    private final AgendaSectionWriter agendaSectionWriter;

    /**
     * 회의 ID로 안건별 섹션 조회
     *
     * @param meetingId 회의 ID
     * @return 안건별 섹션 목록 (안건 번호 순 정렬)
     */
    public List<AgendaSection> getAgendaSectionsByMeeting(String meetingId) {
        log.info("회의 ID로 안건별 섹션 조회: {}", meetingId);
        return agendaSectionReader.findByMeetingId(meetingId);
    }

    /**
     * 회의록 ID로 안건별 섹션 조회
     *
     * @param minutesId 회의록 ID
     * @return 안건별 섹션 목록
     */
    public List<AgendaSection> getAgendaSectionsByMinutes(String minutesId) {
        log.info("회의록 ID로 안건별 섹션 조회: {}", minutesId);
        return agendaSectionReader.findByMinutesId(minutesId);
    }

    /**
     * 안건별 섹션 일괄 저장
     *
     * @param sections 안건 섹션 목록
     * @return 저장된 안건 섹션 목록
     */
    @Transactional
    public List<AgendaSection> saveAgendaSections(List<AgendaSection> sections) {
        log.info("안건별 섹션 일괄 저장: {} 개", sections.size());
        return agendaSectionWriter.saveAll(sections);
    }

    /**
     * 회의 ID로 안건별 섹션 전체 삭제
     *
     * @param meetingId 회의 ID
     */
    @Transactional
    public void deleteAgendaSectionsByMeeting(String meetingId) {
        log.info("회의 ID로 안건별 섹션 전체 삭제: {}", meetingId);
        agendaSectionWriter.deleteByMeetingId(meetingId);
    }
}
