package com.platform.modules.live.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.platform.modules.live.dao.LiveCasterDao;
import com.platform.modules.live.entity.LiveCasterEntity;

import com.platform.modules.live.service.LiveCasterService;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.sql.Wrapper;
import java.util.Arrays;
import java.util.List;

@Service("liveCasterService")
@Transactional
public class LiveCasterServiceImpl extends ServiceImpl<LiveCasterDao, LiveCasterEntity> implements LiveCasterService {

	@Override
	public void save(LiveCasterEntity liveCaster){
		this.baseMapper.insert(liveCaster);
	}
	
	@Override
	public void update(LiveCasterEntity liveCaster){
		this.baseMapper.update(liveCaster, null);
	}
	
	@Override
	public void delete(Integer id){
		this.baseMapper.deleteById(id);
	}
	
	@Override
	public void deleteBatch(Integer[] ids){
		this.baseMapper.deleteBatchIds(Arrays.asList(ids));
	}

	@Override
	@Transactional(readOnly = true)
	public LiveCasterEntity selectByAppNameAndStreamName(String appName, String streamName) {
		EntityWrapper<LiveCasterEntity> wrapper = new EntityWrapper<>();
		wrapper.eq("app_name", appName);
		wrapper.eq("stream_name", streamName);
		List<LiveCasterEntity> liveCasterEntities = this.baseMapper.selectList(wrapper);
		if(liveCasterEntities != null && liveCasterEntities.size() == 1)
			return liveCasterEntities.get(0);
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public LiveCasterEntity selectByCasterId(String casterId) {
		EntityWrapper<LiveCasterEntity> wrapper = new EntityWrapper<>();
		wrapper.eq("caster_id", casterId);
		return selectOne(wrapper);
	}
}
