package com.yonge.cooleshow.biz.dal.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.biz.dal.dao.HotSearchDao;
import com.yonge.cooleshow.biz.dal.dto.search.HotSearchSearch;
import com.yonge.cooleshow.biz.dal.entity.HotSearch;
import com.yonge.cooleshow.biz.dal.service.HotSearchService;
import com.yonge.cooleshow.biz.dal.vo.HotSearchVo;
import com.yonge.cooleshow.common.enums.YesOrNoEnum;
import com.yonge.toolset.base.exception.BizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;


@Service
public class HotSearchServiceImpl extends ServiceImpl<HotSearchDao, HotSearch> implements HotSearchService {
    private final static Logger log = LoggerFactory.getLogger(HotSearchServiceImpl.class);


    @Override
    public boolean update(HotSearch hotSearch) {
        HotSearch search = this.getById(hotSearch.getId());
        if (search == null) {
            throw  new BizException("热门搜索信息不存在");
        }
        if (YesOrNoEnum.YES.getCode().equals(search.getStatus().getCode())) {
            throw new BizException("启用状态下不能修改");
        }

        return this.updateById(hotSearch);

    }

    @Override
    public boolean status(Long hotSearchId) {
        HotSearch search = this.getById(hotSearchId);
        if (search == null) {
            throw  new BizException("热门搜索信息不存在");
        }

        if (YesOrNoEnum.YES.getCode().equals(search.getStatus().getCode())) {
            search.setStatus(YesOrNoEnum.NO);
        } else {
            search.setStatus(YesOrNoEnum.YES);
        }
        return this.updateById(search);
    }

    @Override
    public IPage<HotSearchVo> selectPage(IPage<HotSearchVo> page, HotSearchSearch query) {
        return page.setRecords(baseMapper.selectPage(page,query));
    }
}