package com.style24.scm.biz.service;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.style24.persistence.domain.Notice;
import com.style24.scm.biz.dao.TssNoticeDao;
import com.style24.scm.support.security.session.TssSession;

import lombok.extern.slf4j.Slf4j;

/**
 * 공지사항 Service
 *
 * @author gagamel
 * @since 2020. 10. 30
 */
@Service
@Slf4j
public class TssNoticeService {

	@Autowired
	private TssNoticeDao noticeDao;

	/**
	 * 공지사항 등록(상품상세공지에서 사용)
	 * @param notice - 공지사항 정보
	 * @return
	 * @author eskim
	 * @since 2020. 11. 05
	 */
	@Transactional("shopTxnManager")
	public void createNotice(Notice notice) {
		noticeDao.createNotice(notice);
	}

	/**
	 * 공지사항 수정(상품상세공지에서 사용)
	 * @param notice - 공지사항 정보
	 * @return
	 * @author eskim
	 * @since 2020. 11. 05
	 */
	@Transactional("shopTxnManager")
	public void updateNotice(Notice notice) {
		noticeDao.updateNotice(notice);
	}

	/**
	 * 공지사항 팝업 총건수
	 * @return
	 * @author gagamel
	 * @since 2020. 12. 30
	 */
	public int getNoticePopupTotalCount() {
		return noticeDao.getNoticePopupTotalCount(TssSession.getInfo().getRoleCd());
	}

	/**
	 * 공지사항 팝업 목록
	 * @return
	 * @author gagamel
	 * @since 2020. 12. 29
	 */
	public Collection<Notice> getNoticePopupList() {
		Collection<Notice> noticeList = noticeDao.getNoticePopupList(TssSession.getInfo().getRoleCd());

		if (noticeList != null && !noticeList.isEmpty()) {
			for (Notice notice : noticeList) {
				notice.setFileList(noticeDao.getNoticePopupFileList(notice.getNoticeSq()));
			}
		}

		return noticeList;
	}

}
