package com.slodon.b2b2c.model.live;

import com.slodon.b2b2c.core.response.PagerInfo;
import com.slodon.b2b2c.dao.write.live.LiveGoodsWriteMapper;
import com.slodon.b2b2c.live.dto.LiveGoodsInfoDto;
import com.slodon.b2b2c.live.example.LiveBroadcastExample;
import com.slodon.b2b2c.live.example.LiveGoodsExample;
import com.slodon.b2b2c.live.pojo.LiveBroadcast;
import com.slodon.b2b2c.live.pojo.LiveGoods;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class LiveGoodsModel {

    @Autowired
    private LiveGoodsWriteMapper liveGoodsWriteMapper;

    public void addGoodsCreate(LiveGoodsInfoDto liveGoodsInfoDto) {

        LiveGoods liveGoods = new LiveGoods();
        try {
            PropertyUtils.copyProperties(liveGoods,liveGoodsInfoDto);
        } catch (Exception e) {
            e.printStackTrace();
        }
        liveGoodsWriteMapper.insert(liveGoods);
    }

    public List<LiveGoods> getLivesList(LiveGoodsExample example, PagerInfo pager) {
        List<LiveGoods> goodsList;
        if (pager != null) {
            pager.setRowsCount(liveGoodsWriteMapper.countByExample(example));
            goodsList = liveGoodsWriteMapper.listPageByExample(example, pager.getStart(), pager.getPageSize());
        } else {
            goodsList = liveGoodsWriteMapper.listByExample(example);
        }
        return goodsList;
    }

    public void wxDelLiveGood(Integer goodsId) {
        liveGoodsWriteMapper.deleteByPrimaryKey(goodsId);
    }

    public List<Integer> getLivesGoodsIds() {
        return liveGoodsWriteMapper.getLivesGoodsIds();
    }

    public void updateLivesGoodsType(List<LiveGoods> liveGoodsList) {
        liveGoodsWriteMapper.updateLivesGoodsType(liveGoodsList);
    }

    public List<LiveGoods> getListRelation(String name, Integer roomId) {
        return liveGoodsWriteMapper.getListRelation(name,roomId);
    }
}
