package com.style24.front.biz.service;

import java.util.Collection;

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

import com.style24.front.biz.dao.TsfSocialDao;
import com.style24.front.support.security.session.TsfSession;
import com.style24.persistence.domain.Login;
import com.style24.persistence.domain.Social;

import lombok.extern.slf4j.Slf4j;

/**
 * 소셜(핫딜) Service
 *
 * @author sowon
 * @since 2021. 3. 11
 */
@Service
@Slf4j
public class TsfSocialService {
	
	@Autowired
	private TsfSocialDao socialDao;
	
	/**
	 * 소셜(핫딜) 정보
	 *
	 * @param
	 * @return
	 * @author sowon	
	 * @since 2021. 3. 11
	 */
	public Social getSocialInfo(Social social) {
		return socialDao.getSocialInfo(social);
	}
	
	/**
	 * 소셜(핫딜) 상품 리스트
	 *
	 * @param
	 * @return
	 * @author sowon	
	 * @since 2021. 3. 11
	 */
	public Collection<Social> getSocialGoodsList(Social social) {
		Social info = new Social();
		info = socialDao.getSocialInfo(social);
		
		// TODO 로그인 정보 입력
		if (TsfSession.isLogin()) {
			Login login = TsfSession.getInfo();
			social.setCustNo(login.getCustNo());
		}
		
		if (info!=null) {
			social.setSocialSq(info.getSocialSq());
		}
		
		return socialDao.getSocialGoodsList(social);
	}

	public Social getSocialForGoods(Social social){
		Social socialInfo = socialDao.getSocialInfo(social);

		if (TsfSession.isLogin()) {
			Login login = TsfSession.getInfo();
			social.setCustNo(login.getCustNo());
		}

		if(socialInfo != null){
			social.setSocialSq(socialInfo.getSocialSq());
			socialInfo.setSocialGoodsList(socialDao.getSocialGoodsList(social));
		}

		return socialInfo;
	}
}
