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

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.JgOverDesignServiceLife;
import com.yeejoin.amos.boot.module.jg.api.entity.JgOverDesignServiceLifeEq;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgOverDesignServiceLifeEqServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgOverDesignServiceLifeServiceImpl;
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 OverDesignEditUpdateService {

    private final JgOverDesignServiceLifeServiceImpl overDesignServiceLifeService;

    private final JgOverDesignServiceLifeEqServiceImpl overDesignServiceLifeEqService;

    public Set<String> getEqsByApplyNo(String applyNo) {
        JgOverDesignServiceLife overDesignServiceLifeServiceOne = overDesignServiceLifeService.getOne(new LambdaQueryWrapper<JgOverDesignServiceLife>().eq(JgOverDesignServiceLife::getApplyNo, applyNo).select(BaseEntity::getSequenceNbr));
        List<JgOverDesignServiceLifeEq> eqs = overDesignServiceLifeEqService.list(new LambdaQueryWrapper<JgOverDesignServiceLifeEq>().eq(JgOverDesignServiceLifeEq::getOverDesignId, overDesignServiceLifeServiceOne.getSequenceNbr()).select(JgOverDesignServiceLifeEq::getEquId, BaseEntity::getSequenceNbr));
        return eqs.stream().map(JgOverDesignServiceLifeEq::getEquId).collect(Collectors.toSet());
    }

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

}