package com.style24.admin.biz.service;

import java.util.Collection;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.style24.admin.biz.dao.TsaFaqDao;
import com.style24.persistence.domain.Faq;

import lombok.extern.slf4j.Slf4j;

/**
 * FAQ Service
 *
 * @author gagamel
 * @since 2020. 11. 3
 */
@Service
@Slf4j
public class TsaFaqService {

	@Autowired
	private TsaFaqDao faqDao;

	/**
	 * FAQ 목록
	 * @param faq - FAQ 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 3
	 */
	public Collection<Faq> getFaqList(Faq faq) {
		return faqDao.getFaqList(faq);
	}

	/**
	 * FAQ 등록/수정
	 * @param faq - FAQ 정보
	 * @author gagamel
	 * @since 2020. 11. 3
	 */
	@Transactional("shopTxnManager")
	public void saveFaq(Faq faq) {
		// 내용 유무 확인
		if (StringUtils.isNotBlank(faq.getAnswer())) {
			faq.setAnswer(faq.getAnswer().replaceAll("&lt;", "<").replaceAll("&gt;", ">"));
		}

		faqDao.saveFaq(faq);
	}

	/**
	 * FAQ 상세
	 * @param faqSq - FAQ일련번호
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 3
	 */
	public Faq getFaq(Integer faqSq) {
		return faqDao.getFaq(faqSq);
	}

}
