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

import cn.hutool.core.bean.BeanUtil;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.module.erp.api.dto.internalWarehouse.InternalWarehouseDTO;
import com.zt.plat.module.erp.controller.admin.erp.internalwarehouse.vo.InternalWarehouseRespVO;
import com.zt.plat.module.erp.controller.admin.erp.vo.WarehouseFactoryRespVO;
import com.zt.plat.module.erp.dal.dataobject.erp.internalwarehouse.InternalWarehouseDO;
import com.zt.plat.module.erp.service.erp.WarehouseFactoryService;
import com.zt.plat.module.erp.service.erp.internalwarehouse.InternalWarehouseService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

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

@RestController
@Validated
@Slf4j
public class InternalWarehouseImpl implements InternalWarehouseApi {
    @Resource
    private InternalWarehouseService internalWarehouseService;
    @Resource
    private WarehouseFactoryService warehouseFactoryService;
    @Override
    public CommonResult<List<InternalWarehouseDTO>>getInternalWarehouseListByFactoryCodeAndWarehouseCode(String factoryCode, String warehouseCode, String mmsiType,String operationType) {
        InternalWarehouseDO internalWarehouse = internalWarehouseService.getInternalWarehouseByFactoryCodeAndWarehouseCode(factoryCode, warehouseCode);
        if (internalWarehouse == null){
            return success(new ArrayList<>());
        }
        List<WarehouseFactoryRespVO> warehouseFactoryByParams = warehouseFactoryService.getWarehouseFactoryByParams(internalWarehouse.getId(), mmsiType, operationType);
        return success(BeanUtil.copyToList(warehouseFactoryByParams, InternalWarehouseDTO.class));
    }
}
