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.TsaClauseDao;
import com.style24.admin.support.security.session.TsaSession;
import com.style24.persistence.domain.Clause;

import lombok.extern.slf4j.Slf4j;

/**
 * 약관 Service
 *
 * @author gagamel
 * @since 2020. 10. 29
 */
@Service
@Slf4j
public class TsaClauseService {

	@Autowired
	private TsaClauseDao clauseDao;

	/**
	 * 약관 목록
	 * @param clause - 약관 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 29
	 */
	public Collection<Clause> getClauseList(Clause clause) {
		return clauseDao.getClauseList(clause);
	}

	/**
	 * 약관 상세
	 * @param clause - 약관 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 29
	 */
	public Clause getClauseDetail(Integer clauseSq) {
		return clauseDao.getClauseDetail(clauseSq);
	}

	/**
	 * 약관 생성/수정
	 * @param clause - 약관 정보
	 * @author gagamel
	 * @since 2020. 10. 29
	 */
	@Transactional("shopTxnManager")
	public void saveClause(Clause clause) {
		clause.setRegNo(TsaSession.getInfo().getUserNo());
		clause.setUpdNo(TsaSession.getInfo().getUserNo());

		if (clause.getMode().equals("N")) {
			clauseDao.createClause(clause);
		} else {
			clauseDao.updateClause(clause);
		}
	}

}
