package org.springblade.modules.martial.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.modules.martial.mapper.MartialCompetitionAttachmentMapper;
import org.springblade.modules.martial.pojo.entity.MartialCompetitionAttachment;
import org.springblade.modules.martial.service.IMartialCompetitionAttachmentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 赛事附件 服务实现类
 *
 * @author BladeX
 */
@Service
public class MartialCompetitionAttachmentServiceImpl extends ServiceImpl<MartialCompetitionAttachmentMapper, MartialCompetitionAttachment> implements IMartialCompetitionAttachmentService {

	@Override
	public List<MartialCompetitionAttachment> getByCompetitionIdAndType(Long competitionId, String attachmentType) {
		LambdaQueryWrapper<MartialCompetitionAttachment> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(MartialCompetitionAttachment::getCompetitionId, competitionId)
			.eq(MartialCompetitionAttachment::getAttachmentType, attachmentType)
			.eq(MartialCompetitionAttachment::getStatus, 1)
			.orderByAsc(MartialCompetitionAttachment::getOrderNum);
		return this.list(wrapper);
	}

	@Override
	public List<MartialCompetitionAttachment> getByCompetitionId(Long competitionId) {
		LambdaQueryWrapper<MartialCompetitionAttachment> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(MartialCompetitionAttachment::getCompetitionId, competitionId)
			.eq(MartialCompetitionAttachment::getStatus, 1)
			.orderByAsc(MartialCompetitionAttachment::getAttachmentType)
			.orderByAsc(MartialCompetitionAttachment::getOrderNum);
		return this.list(wrapper);
	}

	@Override
	public boolean removeByCompetitionIdAndType(Long competitionId, String attachmentType) {
		LambdaQueryWrapper<MartialCompetitionAttachment> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(MartialCompetitionAttachment::getCompetitionId, competitionId)
			.eq(MartialCompetitionAttachment::getAttachmentType, attachmentType);
		return this.remove(wrapper);
	}

}
