package com.pusong.business.service.approver.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pusong.business.domain.*;
import com.pusong.business.domain.bo.PsApproverRecordBo;
import com.pusong.business.domain.vo.PsApproverRecordVo;
import com.pusong.business.domain.vo.PsCompanyInfoVo;
import com.pusong.business.domain.vo.PsContractInfoVo;
import com.pusong.business.domain.vo.PsContractPayVo;
import com.pusong.business.enums.ApproverTypeEnum;
import com.pusong.business.enums.ContractStatusEnum;
import com.pusong.business.enums.PayStatusEnum;
import com.pusong.business.enums.TaskStatusEnum;
import com.pusong.business.mapper.PsApproverRecordMapper;
import com.pusong.business.mapper.PsContractPayMapper;
import com.pusong.business.mapper.PsTaskAppointMapper;
import com.pusong.business.mapper.PsTaskMainMapper;
import com.pusong.business.service.IPsCompanyInfoService;
import com.pusong.business.service.IPsContractInfoService;
import com.pusong.business.service.IPsTaskService;
import com.pusong.common.core.utils.DateUtils;
import com.pusong.common.core.utils.StringUtils;
import com.pusong.common.mybatis.core.page.PageQuery;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 退款审批()
 */
@RequiredArgsConstructor
@Service
@Slf4j
public class ReturnApproverServiceImpl extends ApproverAbstractServiceImpl {
    @Resource
    private PsApproverRecordMapper recordMapper;
    @Override
    public String approverType() {
        return ApproverTypeEnum.RETURN.getCode();
    }
    private final PsContractPayMapper baseMapper;

    private final PsContractPayMapper payMapper;

    @Resource
    private IPsCompanyInfoService companyInfoService;
    /**
     * 1 审批成功 退款审批成功
     * @param psApproverRecord 神瀑类
     */
    @Override
    public void success(PsApproverRecord psApproverRecord) {
        PsContractPay info = baseMapper.selectById(psApproverRecord.getBusinessId());
        info.setPayStatus(PayStatusEnum.PAYING.getCode());
        baseMapper.updateById(info);
    }

    /**
     * 审批拒绝 退款审批失败
     * @param psApproverRecord
     */
    @Override
    public void fail(PsApproverRecord psApproverRecord) {
        PsContractPay info = baseMapper.selectById(psApproverRecord.getBusinessId());
        info.setPayStatus(PayStatusEnum.FILE.getCode());
        baseMapper.updateById(info);
    }


//    @Override
//    public Page<PsApproverRecordVo> queryList(PsApproverRecordBo bo, PageQuery pageQuery){
//        Page<PsApproverRecordVo> res = super.queryList(bo, pageQuery);
//        for (PsApproverRecordVo record : res.getRecords()) {
//            PsContractPayVo psContractPayVo = payMapper.selectVoById(record.getBusinessId());
//            record.setPsContractPayVo(psContractPayVo);
//        }
//        return res;
//    }
}
