package com.persagy.dmp.simple.client;

import cn.hutool.extra.spring.SpringUtil;
import com.persagy.dmp.basic.dto.RequestData;
import com.persagy.dmp.common.model.response.CommonResult;
import com.persagy.dmp.common.utils.ResultHelper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * 数字孪生 简洁API Client门面
 * @author Charlie Yu
 * @date 2021-05-15
 */
public class DigitalObjectSimpleFacade {

    private static DigitalObjectSimpleClient client = SpringUtil.getBean(DigitalObjectSimpleClient.class);

    /**
     * 根据项目ID查询设备数量和待报废设备数量统计
     * @param groupCode: 集团编码
     * @param appId: 应用ID
     * @param userId: 用户ID
     * @param projectIds: 项目ID - 为空查所有
     * @return
     */
    public static List<Map<String, Object>> queryExpectScrapCountByProjects(@RequestParam("groupCode") String groupCode,
                                                                            @RequestParam("appId") String appId,
                                                                            @RequestParam("userId") String userId,
                                                                            @RequestBody(required = false) List<String> projectIds) {
        CommonResult<List<Map<String, Object>>> result = client.queryExpectScrapCountByProjects(groupCode, appId, userId, projectIds);
        return ResultHelper.getContent(result);
    }

    /**
     * 根据对象信息点统计数量
     * @param groupCode: 集团编码
     * @param appId: 应用ID
     * @param userId: 用户ID
     * @param requestData: 请求参数
     * @return
     */
    public static List<Map<String, Object>> queryObjectCountByObjInfos(String groupCode, String appId, String userId, RequestData requestData) {
        CommonResult<List<Map<String, Object>>> result = client.queryObjectCountByObjInfos(groupCode, appId, userId, requestData);
        return ResultHelper.getContent(result);
    }


    /**
     * 查询当前设备类型下的部件分类以及数量
     * @param groupCode: 集团编码
     * @param appId: 应用ID
     * @param userId: 用户ID
     * @param requestData: 请求参数
     * @return
     */
    public static List<Map<String, Object>> queryComponentsCountByEquipId(String groupCode, String projectId, String appId, String userId, RequestData requestData) {
        CommonResult<List<Map<String, Object>>> result = client.queryComponentsCountByEquipId(groupCode, projectId,appId, userId, requestData);
        return ResultHelper.getContent(result);
    }

    /**
     * 统计项目下允许创建的部件类型，以及项目下创建的部件数量
     * @param groupCode: 集团编码
     * @param appId: 应用ID
     * @param userId: 用户ID
     * @param requestData: 请求参数
     * @return
     */
    public static List<Map<String, Object>> queryEquipComponentsByProjectId(String groupCode, String projectId, String appId, String userId, RequestData requestData) {
        CommonResult<List<Map<String, Object>>> result = client.queryEquipComponentsByProjectId(groupCode, projectId,appId, userId, requestData);
        return ResultHelper.getContent(result);
    }

    /**
     * 项目下所有实例(system/space/equipment..)类型以及名称
     * @param groupCode: 集团编码
     * @param appId: 应用ID
     * @param userId: 用户ID
     * @param requestData: 请求参数
     * @return
     */
    public static List<Map<String, Object>> queryDefineInfoByObjType(@RequestParam("groupCode") String groupCode, @RequestParam("projectId") String projectId,
                                                                          @RequestParam("appId") String appId,
                                                                          @RequestParam("userId") String userId, @RequestBody RequestData requestData){
        CommonResult<List<Map<String, Object>>> result = client.queryDefineInfoByObjType(groupCode, projectId,appId, userId, requestData);
        return ResultHelper.getContent(result);

    }


    /**
     * 查询不确定楼层/不确定建筑 的系统
     * @param groupCode: 集团编码
     * @param appId: 应用ID
     * @param userId: 用户ID
     * @param requestData: 请求参数
     * @return
     */
    public static List<Map<String, Object>> queryNotSureSystem(@RequestParam("groupCode") String groupCode, @RequestParam("projectId") String projectId,
                                                                     @RequestParam("appId") String appId,
                                                                     @RequestParam("userId") String userId, @RequestBody RequestData requestData){
        CommonResult<List<Map<String, Object>>> result = client.queryNotSureSystem(groupCode, projectId,appId, userId, requestData);
        return ResultHelper.getContent(result);

    }
}
