package com.zt.plat.module.erp.api;

import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.erp.api.dto.ErpMaterialDTO;
import com.zt.plat.module.erp.api.dto.ErpProductiveVersionReqDTO;
import com.zt.plat.module.erp.api.dto.ErpQueryReqDTO;
import com.zt.plat.module.erp.api.dto.ErpSubmitReqDTO;
import com.zt.plat.module.erp.controller.admin.erp.vo.ErpMaterialRespVO;
import com.zt.plat.module.erp.service.erp.ErpMaterialService;
import com.zt.plat.module.erp.service.erp.ErpProductiveVersionService;
import com.zt.plat.module.erp.utils.ErpConfig;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

import static com.zt.plat.framework.common.pojo.CommonResult.success;

/**
 * ERP  Api 实现类
 *
 * @author ZT
 * @author jason
 */
@RestController
@Validated
@Component
public class ErpExternalApiImpl implements ErpExternalApi {

    @Resource
    private ErpConfig erpConfig;
    @Resource
    private ErpProductiveVersionService erpProductiveVersionService;
    @Resource
    private ErpMaterialService erpMaterialService;


    @Override
    public HashMap<String, String> submitDataToErp(ErpSubmitReqDTO reqDTO) {
        return erpConfig.pushDataToErp(reqDTO);
    }

    @Override
    public HashMap<String, Object> queryDataToErp(ErpQueryReqDTO reqDTO) {
        String funcnr = reqDTO.getFuncnr();
        Map<String, Object> req = reqDTO.getReq();
        return erpConfig.fetchDataFromERP(funcnr, req);
    }

    @Override
    public CommonResult<String> getErpProductiveVersionByFM(ErpProductiveVersionReqDTO reqDTO) {
        String productiveVersionNumber = erpProductiveVersionService.getErpProductiveVersionByFM(reqDTO);
        return success(productiveVersionNumber);
    }

    @Override
    public CommonResult<String> getMaterialUnit(String materialNumber) {
        String materialUnit = erpMaterialService.getMaterialUnit(materialNumber);
        return success(materialUnit);
    }
}
