package com.goafanti.star.service.impl;

import java.util.List;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.goafanti.common.dao.StarMapper;
import com.goafanti.common.enums.StarHotType;
import com.goafanti.common.enums.StarType;
import com.goafanti.common.model.Star;
import com.goafanti.common.utils.LoggerUtils;
import com.goafanti.star.bo.BigShotStarInterest;
import com.goafanti.star.bo.BigShotStarListBo;
import com.goafanti.star.bo.HotStarListBo;
import com.goafanti.star.service.StarService;

@Service
public class StarServiceImpl implements StarService {

	private static final Logger	logger	= LoggerFactory.getLogger(StarServiceImpl.class);

	@Autowired
	private StarMapper			starMapper;

	@Override
	public List<HotStarListBo> listHotStar() {
		return starMapper.listHostStar();
	}

	@Override
	public List<HotStarListBo> listStarList(String uid) {
		return starMapper.listStarList(uid);
	}

	@Override
	public void save(List<Star> starList, String[] hot) {
		starMapper.deleteAll();
		for (Star s : starList) {
			s.setId(UUID.randomUUID().toString());
			s.setHot(StarHotType.UNHOT.getCode());
		}
		
		Star star = null;
		for (String ss : hot){
			star = new Star();
			star.setId(UUID.randomUUID().toString());
			star.setUid(ss);
			star.setHot(StarHotType.HOT.getCode());
			star.setStar(StarType.UNSTAR.getCode());
			starList.add(star);
		}

		starMapper.insertBatch(starList);
	}

	@Override
	@Cacheable(value = "BigShotStarListCache", key = "'BigShotStarList:'+#bigShotStarCacheKey")
	public List<BigShotStarListBo> listBigShotStar(Integer bigShotStarCacheKey) {
		return starMapper.listBigShotStar();
	}

	@Override
	@CacheEvict(value = "BigShotStarListCache", key = "'BigShotStarList:'+#bigShotStarCacheKey")
	public void clearBigShotStarList(Integer bigShotStarCacheKey) {
		LoggerUtils.debug(logger, "清除大咖说科技明星列表缓存:[%s]", bigShotStarCacheKey);
	}

	@Override
	public List<BigShotStarInterest> findBigShotInterestStatus(String uid) {
		return starMapper.findBigShotInterestStatus(uid);
	}

	@Override
	public List<BigShotStarInterest> findStarInterestStatus(String uid) {
		return starMapper.findStarInterestStatus(uid);
	}

}
