package com.gic.haoban.manage.web.controller.content.adaptor;

import com.gic.api.base.commons.ServiceResponse;
import com.gic.content.api.dto.material.ContentMaterialBaseDTO;
import com.gic.content.api.service.ContentMaterialApiService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author MUSI
 * @Date 2023/3/29 11:39 AM
 * @Description
 * @Version
 **/

@Slf4j
@Component
public class ContentMaterialAdaptor {

    @Autowired
    private ContentMaterialApiService contentMaterialApiService;

    /**
     * 查询素材基本信息
     * @param enterpriseId
     * @param materialIds
     * @return
     */
    public Map<Long, ContentMaterialBaseDTO> queryMaterialInfoMap(String enterpriseId, List<Long> materialIds) {
        ServiceResponse<List<ContentMaterialBaseDTO>> serviceResponse = contentMaterialApiService.listMaterialIdByMaterialIdList(enterpriseId, materialIds, null);
        if (!serviceResponse.isSuccess()) {
            return Collections.emptyMap();
        }

        if (CollectionUtils.isEmpty(serviceResponse.getResult())) {
            return Collections.emptyMap();
        }
        return serviceResponse
                .getResult()
                .stream()
                .collect(Collectors.toMap(ContentMaterialBaseDTO::getContentMaterialId, Function.identity()));
    }
}
