package org.dromara.main.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.main.domain.MainBackCandidate;
import org.dromara.main.domain.bo.MainPostCandidateQueryBo;
import org.dromara.main.domain.bo.MainPostCandidateStatusBo;
import org.dromara.main.domain.vo.MainPostCandidateVo;
import org.dromara.main.mapper.MainBackCandidateMapper;
import org.dromara.main.service.IMainPostCandidateService;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class MainPostCandidateServiceImpl implements IMainPostCandidateService {

    private final MainBackCandidateMapper mainBackCandidateMapper;

    @Override
    public TableDataInfo<MainPostCandidateVo> queryPageList(MainPostCandidateQueryBo bo, PageQuery pageQuery) {
        if (bo.getPostId() == null) {
            throw new ServiceException("岗位ID不能为空");
        }
        IPage<MainPostCandidateVo> page = mainBackCandidateMapper.selectPostCandidatePage(pageQuery.build(), bo);
        return TableDataInfo.build(page);
    }

    @Override
    public Boolean updateStatus(MainPostCandidateStatusBo bo) {
        if (bo.getId() == null) {
            throw new ServiceException("报名记录ID不能为空");
        }
        if (bo.getStatus() == null || bo.getStatus().isBlank()) {
            throw new ServiceException("状态不能为空");
        }
        MainBackCandidate entity = new MainBackCandidate();
        entity.setId(bo.getId());
        entity.setStatus(bo.getStatus());
        entity.setRemark(bo.getRemark());
        return mainBackCandidateMapper.updateById(entity) > 0;
    }
}
