package jnpf.cultivate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.cultivate.mapper.FtbCultivatePositionCourseCertificateMapper;
import jnpf.cultivate.service.FtbCultivatePositionCourseCertificateService;
import jnpf.model.cultivate.dto.learn.BatchCommonCountDto;
import jnpf.model.cultivate.po.FtbCultivatePositionCourseCertificate;
import jnpf.model.cultivate.v2.position.vo.FtbCultivatePositionCourseCertificateWithNameVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
*
*
*@Author: peng.hao
*@create: 2024/9/10:10:30
*/
@Service
public class FtbCultivatePositionCourseCertificateServiceImpl extends ServiceImpl<FtbCultivatePositionCourseCertificateMapper, FtbCultivatePositionCourseCertificate> implements FtbCultivatePositionCourseCertificateService {

    @Resource
    private FtbCultivatePositionCourseCertificateMapper ftbCultivatePositionCourseCertificateMapper;

    @Override
    public Map<String, Long> countByPositionLearnIds(List<String> positionLearnIds) {
        if (positionLearnIds == null || positionLearnIds.isEmpty()) {
            return Map.of();
        }
        
        List<BatchCommonCountDto> result = ftbCultivatePositionCourseCertificateMapper.countByPositionLearnIds(positionLearnIds);
        return result.stream()
                .collect(Collectors.toMap(
                        BatchCommonCountDto::getSelectKey,
                        dto -> dto.getNum().longValue(),
                        (existing, replacement) -> existing
                ));
    }

    @Override
    public List<FtbCultivatePositionCourseCertificate> listByPostLearnId(String postLearnId) {
        return ftbCultivatePositionCourseCertificateMapper.listByPostLearnId(postLearnId);
    }
    
    @Override
    public List<FtbCultivatePositionCourseCertificate> listByPostLearnIdAndCourseIds(String postLearnId, List<String> courseIds) {
        if (courseIds == null || courseIds.isEmpty()) {
            return List.of();
        }
        
        return ftbCultivatePositionCourseCertificateMapper.listByPostLearnIdAndCourseIds(postLearnId, courseIds);
    }

    /**
     * 根据岗位学习ID查询证书列表（包含证书名称）
     *
     * @param postLearnId 岗位学习ID
     * @return 证书列表（包含证书名称）
     */
    @Override
    public List<FtbCultivatePositionCourseCertificateWithNameVo> listByPostLearnIdWithName(String postLearnId) {
        return ftbCultivatePositionCourseCertificateMapper.listByPostLearnIdWithName(postLearnId);
    }

    /**
     * 根据岗位学习 ID 和课程 IDs 查询证书列表（包含证书名称）
     *
     * @param postLearnId 岗位学习 ID
     * @param courseIds   课程 ID 列表
     * @return 证书列表（包含证书名称）
     */
    @Override
    public List<FtbCultivatePositionCourseCertificateWithNameVo> listByPostLearnIdAndCourseIdsWithName(String postLearnId, List<String> courseIds) {
        if (courseIds == null || courseIds.isEmpty()) {
            return List.of();
        }
        return ftbCultivatePositionCourseCertificateMapper.listByPostLearnIdAndCourseIdsWithName(postLearnId, courseIds);
    }
}