package beilv.competition.service.impl;

import java.util.List;

import beilv.competition.domain.Competition;
import beilv.competition.mapper.CompetitionMapper;
import beilv.competition.service.ICompetitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import beilv.common.core.text.Convert;

/**
 * 赛事发布Service业务层处理
 *
 * @author LG
 * @date 2024-12-31
 */
@Service
public class CompetitionServiceImpl implements ICompetitionService {
    @Autowired
    private CompetitionMapper competitionMapper;

    private final static String DAI_FA_BU = "competiton_state_1";
    private final static String BAO_MING_ZHONG = "competiton_state_2";
    private final static String BAO_MING_JIE_SHU = "competiton_state_3";
    private final static String YI_GUAN_BI = "competiton_state_4";

    /**
     * 查询赛事发布
     *
     * @param id 赛事发布主键
     * @return 赛事发布
     */
    @Override
    public Competition selectCompetitionById(Integer id) {
        return competitionMapper.selectCompetitionById(id);
    }

    /**
     * 查询赛事发布列表
     *
     * @param competition 赛事发布
     * @return 赛事发布
     */
    @Override
    public List<Competition> selectCompetitionList(Competition competition) {
        return competitionMapper.selectCompetitionList(competition);
    }

    /**
     * 新增赛事发布
     *
     * @param competition 赛事发布
     * @return 结果
     */
    @Override
    public int insertCompetition(Competition competition) {
        competition.setCompetitionState(DAI_FA_BU);
        /*int a = competition.getPersonMax() != null ? competition.getPersonMax() : 0;
        int b = competition.getTeamMax() != null ? competition.getTeamMax() : 0;
        competition.setCompetitionMaximum(a * b);*/
        return competitionMapper.insertCompetition(competition);
    }

    /**
     * 修改赛事发布
     *
     * @param competition 赛事发布
     * @return 结果
     */
    @Override
    public int updateCompetition(Competition competition) {
        return competitionMapper.updateCompetition(competition);
    }

    /**
     * 批量删除赛事发布
     *
     * @param ids 需要删除的赛事发布主键
     * @return 结果
     */
    @Override
    public int deleteCompetitionByIds(String ids) {
        return competitionMapper.deleteCompetitionByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除赛事发布信息
     *
     * @param id 赛事发布主键
     * @return 结果
     */
    @Override
    public int deleteCompetitionById(Integer id) {
        return competitionMapper.deleteCompetitionById(id);
    }

    @Override
    public int publishCompetitionById(String id) {
        Competition competition = new Competition();
        competition.setId(Integer.valueOf(id));
        competition.setCompetitionState(BAO_MING_ZHONG);
        return competitionMapper.publishCompetition(competition);
    }

    @Override
    public int closeCompetitionById(String id) {
        //查询已经缴费的用户

        //调用退费接口

        //修改赛事状态
        Competition competition = new Competition();
        competition.setId(Integer.valueOf(id));
        competition.setCompetitionState(YI_GUAN_BI);
        return competitionMapper.publishCompetition(competition);
    }

    @Override
    public List<Competition> getCompetitionList() {
        return competitionMapper.getCompetitionList();
    }
}
