package com.yeejoin.amos.boot.module.jg.biz.edit.process.biz.changeRegistrationReform;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.module.jg.api.entity.JgChangeRegistrationReform;
import com.yeejoin.amos.boot.module.jg.api.entity.JgChangeRegistrationReformEq;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgChangeRegistrationReformEqServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgChangeRegistrationReformServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgChangeRegistrationReformEqServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgChangeRegistrationReformServiceImpl;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Getter
public class ChangeRegistrationReformEditUpdateService {

    private final JgChangeRegistrationReformServiceImpl mainService;

    private final JgChangeRegistrationReformEqServiceImpl eqService;

    public Set<String> getEqsByApplyNo(String applyNo) {
        JgChangeRegistrationReform jgChangeRegistrationReform = mainService.getOne(new LambdaQueryWrapper<JgChangeRegistrationReform>().eq(JgChangeRegistrationReform::getApplyNo, applyNo).select(BaseEntity::getSequenceNbr));
        List<JgChangeRegistrationReformEq> eqs = eqService.list(new LambdaQueryWrapper<JgChangeRegistrationReformEq>().eq(JgChangeRegistrationReformEq::getEquipTransferId, jgChangeRegistrationReform.getSequenceNbr()).select(JgChangeRegistrationReformEq::getEquId));
        return eqs.stream().map(JgChangeRegistrationReformEq::getEquId).collect(Collectors.toSet());
    }

    public JgChangeRegistrationReform getOneByApplyNo(String applyNo) {
        return mainService.getOne(new LambdaQueryWrapper<JgChangeRegistrationReform>().eq(JgChangeRegistrationReform::getApplyNo, applyNo));
    }

}