package com.prolog.cs.biz.outbound.service;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.prolog.cs.biz.outbound.model.dto.ContainerConfirmDto;
import com.prolog.cs.biz.outbound.model.dto.InfTaskOutBackDTO;
import com.prolog.cs.biz.outbound.model.dto.WmsOutPriorityReqDTO;
import com.prolog.cs.biz.outbound.model.entity.OmsInfCxpsdBill;
import com.prolog.cs.biz.outbound.model.vo.InfTaskOutVO;
import com.prolog.cs.biz.outbound.utils.IntegrationUtil;
import com.prolog.framework.common.message.RestMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

@Component
public class IntegrationRepository {

    @Autowired
    private IntegrationUtil integrationUtil;

    public RestMessage<?> priorityRequest(List<WmsOutPriorityReqDTO> wmsOutPriorityReqList){
        return JSONObject.parseObject(this.askIntegration("/api/siyuan/v1/outbound/pull/priorityRequest", wmsOutPriorityReqList), new TypeReference<RestMessage<?>>(){});
    }

    public RestMessage<?> outBoundRequest(List<InfTaskOutVO> infTaskOutVOS){
        return JSONObject.parseObject(this.askIntegration("/api/siyuan/v1/outbound/pull/outBoundRequest", infTaskOutVOS), new TypeReference<RestMessage<?>>(){});
    }

    public RestMessage<?> confirmContainer(ContainerConfirmDto dto){
        return JSONObject.parseObject(this.askIntegration("/api/yj/v1/outbound/confirmContainer", dto), new TypeReference<RestMessage<?>>(){});
    }

    private String askIntegration(String path, Object param){
        return integrationUtil.askIntegration(path, Collections.singletonMap("params", param)).toJSONString();
    }

    public RestMessage<?> getCxwlStationInfo(String wdmch){
        return JSONObject.parseObject(this.askIntegration("/api/mes/search-logistics", wdmch), new TypeReference<RestMessage<?>>(){});
    }

    public RestMessage<?> cxToErp(List<OmsInfCxpsdBill> omsInfCxpsdBill) {
        return JSONObject.parseObject(this.askIntegration("/api/siyuan/v1/outbound/cxToErp", omsInfCxpsdBill), new TypeReference<RestMessage<?>>(){});
    }
}
