package cn.iocoder.yudao.module.bpm.dal.mysql.business;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.bpm.controller.admin.business.vo.BpmApplyAccommodationPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.elderly.BpmElderlyInfoVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.elderly.ElderlyLogRecordVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmMyPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstancePageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.business.BpmBusinessFormDO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Mapper
public interface BpmBusinessFormMapper extends BaseMapperX<BpmBusinessFormDO> {


    // TODO 条件没写
    default PageResult<BpmBusinessFormDO> selectPage(Long userId, BpmApplyAccommodationPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BpmBusinessFormDO>()
                .eqIfPresent(BpmBusinessFormDO::getUserId, reqVO.getUserId())
                .eqIfPresent(BpmBusinessFormDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BpmBusinessFormDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .betweenIfPresent(BpmBusinessFormDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BpmBusinessFormDO::getId));
    }

    ElderlyLogRecordVO getElderlyInfoByInstanceId(String processInstanceId);

    List<BpmElderlyInfoVO> selectMyBpmPage(@Param("loginUserId") Long loginUserId, Page<BpmElderlyInfoVO> page,
                                           @Param("pageVO") BpmMyPageReqVO pageReqVO);

    List<BpmElderlyInfoVO> selectMyBpmPagTest(@Param("loginUserId") Long loginUserId,
                                           @Param("pageVO") BpmMyPageReqVO pageReqVO);

    List<BpmElderlyInfoVO> getElderMapByBusinessKey(@Param("businessKeys") Set<String> businessKeys);

    List<BpmElderlyInfoVO> getElderMapByProcessInstanceId(@Param("processInstanceIds") Set<String> processInstanceIds);

    List<BpmElderlyInfoVO> selectCopyPage(@Param("loginUserId") Long loginUserId, Page<BpmElderlyInfoVO> page,
                                          @Param("pageVO")BpmMyPageReqVO pageReqVO);

    List<BpmElderlyInfoVO> selectMyMessagePage(@Param("loginUserId") Long loginUserId, Page<BpmElderlyInfoVO> page, @Param("pageVO") BpmMyPageReqVO pageReqVO);

    List<BpmTaskRespVO> getTenantNameList(@Param("processInstanceIds") Set<String> processInstanceIds);

    List<BpmElderlyInfoVO> getReadList(@Param("ids") Set<String> ids, Long userId);

    default Long selectCountByUserId(Long userId) {
        return selectCount(new LambdaQueryWrapperX<BpmBusinessFormDO>()
                .eq(BpmBusinessFormDO::getCreator, userId)
                .eq(BpmBusinessFormDO::getReadStatus, 0)
                .eq(BpmBusinessFormDO::getDeleted, 0));
    }

}
