package jnpf.storecertificatephoto.helper;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jnpf.model.storecertificatephoto.po.StoreCertificatePhotoEntity;
import jnpf.storecertificatephoto.mapper.StoreCertificatePhotoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Component
public class StoreCertificatePhotoHelper {

    @Autowired
    private StoreCertificatePhotoMapper storeCertificatePhotoMapper;

    public Map<String,String> buildStoreCertificateIdAndNames(Collection<String> templateIds,Integer status){
        if(CollectionUtil.isEmpty(templateIds)){
            return Collections.emptyMap();
        }
        LambdaQueryWrapper<StoreCertificatePhotoEntity> queryWrapper = new LambdaQueryWrapper<StoreCertificatePhotoEntity>()
                .select(StoreCertificatePhotoEntity::getId, StoreCertificatePhotoEntity::getCertificateName)
                .in(StoreCertificatePhotoEntity::getId, templateIds);
        if(Objects.nonNull(status)){
            queryWrapper.eq(StoreCertificatePhotoEntity::getStatus, status);
        }
        return storeCertificatePhotoMapper.selectList(queryWrapper)
                .stream()
                .collect(Collectors.toMap(StoreCertificatePhotoEntity::getId, StoreCertificatePhotoEntity::getCertificateName));
    }

    public Map<String,StoreCertificatePhotoEntity> buildStoreCertificateById(Collection<String> templateIds,Integer status){
        if(CollectionUtil.isEmpty(templateIds)){
            return Collections.emptyMap();
        }
        LambdaQueryWrapper<StoreCertificatePhotoEntity> queryWrapper = new LambdaQueryWrapper<StoreCertificatePhotoEntity>()
                .in(StoreCertificatePhotoEntity::getId, templateIds);
        if(Objects.nonNull(status)){
            queryWrapper.eq(StoreCertificatePhotoEntity::getStatus, status);
        }
        return storeCertificatePhotoMapper.selectList(queryWrapper)
                .stream()
                .collect(Collectors.toMap(StoreCertificatePhotoEntity::getId, v->v));
    }

}