package com.gic.haoban.manage.service.service.content.adaptor;

import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.enterprise.api.dto.enterprise.EnterpriseUsingStatusDTO;
import com.gic.enterprise.api.service.EnterpriseUseForbidService;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @Author MUSI
 * @Date 2023/4/2 10:05 PM
 * @Description
 * @Version
 **/
@Slf4j
@Component
public class MaterialEnterpriseAdaptor {

    @Getter
    @AllArgsConstructor
    public enum MaterialLevel {
        LOW(1, "低版本"),
        HIGH(2, "高版本");
        private Integer code;
        private String desc;
    }

    @Autowired
    EnterpriseUseForbidService enterpriseUseForbidService;

    /**
     * @see MaterialLevel
     * @param highLevel 1 低版本; 2高版本
     * @return
     */
    public List<String> queryHasRightEnterpriseIds(Integer highLevel) {

        ServiceResponse<List<EnterpriseUsingStatusDTO>> serviceResponse = enterpriseUseForbidService.getUseEnterpriseByCode("", null);
        if (!serviceResponse.isSuccess()) {
            log.info("查询企业信息异常 {}", JSON.toJSONString(serviceResponse));
            return Collections.emptyList();
        }
        return serviceResponse.getResult()
                .stream()
                .filter(item -> Objects.equals(item.getVersion(), highLevel))
                .filter(item -> Boolean.TRUE.equals(item.getVaild()))
                .map(EnterpriseUsingStatusDTO::getEnterpriseId)
                .collect(Collectors.toList());
    }
}
