package com.style24.admin.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.admin.biz.dao.TsaCounselDao;
import com.style24.admin.support.security.session.TsaSession;
import com.style24.persistence.domain.Counsel;

import lombok.extern.slf4j.Slf4j;

/**
 * 상담(1:1문의) Service
 *
 * @author gagamel
 * @since 2020. 12. 24
 */
@Service
@Slf4j
public class TsaCounselService {

	@Autowired
	private TsaCounselDao counselDao;

	/**
	 * 1:1문의 목록
	 * @param counsel -상담정보
	 * @return
	 * @author gagamel
	 * @since 2020. 12. 24
	 */
	public Collection<Counsel> getOneToOneQnaList(Counsel counsel) {
		return counselDao.getOneToOneQnaList(counsel);
	}

	/**
	 * 1:1문의 상세
	 * @param counselSq - 상담일련번호
	 * @return
	 * @author gagamel
	 * @since 2020. 12. 24
	 */
	public Counsel getOneToOneQna(Integer counselSq) {
		Counsel counsel = new Counsel();
		counsel.setCounselSq(counselSq);
		return counselDao.getOneToOneQna(counsel);
	}

	/**
	 * 문의 답변 저장
	 * @param counsel - 상담정보
	 * @author gagamel
	 * @since 2020. 12. 24
	 */
	@Transactional("shopTxnManager")
	public void updateQnaAnswer(Counsel counsel) {
		counselDao.updateQnaAnswer(counsel);
	}

	/**
	 * 상품문의 목록
	 * @param counsel -상담정보
	 * @return
	 * @author gagamel
	 * @since 2020. 12. 24
	 */
	public Collection<Counsel> getGoodsQnaList(Counsel counsel) {
		counsel.setRoleCd(TsaSession.getInfo().getRoleCd());
		counsel.setSupplyCompCd(TsaSession.getInfo().getSupplyCompCd());
		return counselDao.getGoodsQnaList(counsel);
	}

	/**
	 * 상품문의 상세
	 * @param counselSq - 상담일련번호
	 * @return
	 * @author gagamel
	 * @since 2020. 12. 24
	 */
	public Counsel getGoodsQna(Integer counselSq) {
		Counsel counsel = new Counsel();
		counsel.setCounselSq(counselSq);
		counsel.setRoleCd(TsaSession.getInfo().getRoleCd());
		counsel.setSupplyCompCd(TsaSession.getInfo().getSupplyCompCd());
		return counselDao.getOneToOneQna(counsel);
	}

	/**
	 * 상품문의 입점업체에 답변의뢰 (입점상품인 경우)
	 * @param counsel - 상담 정보
	 * @author gagamel
	 * @since 2020. 12. 24
	 */
	@Transactional("shopTxnManager")
	public void updateGoodsQnaAnswerTransfer(Counsel counsel) {
		counselDao.updateGoodsQnaAnswerTransfer(counsel);
	}

}
