package com.yc.ship.module.resource.api;

import com.yc.ship.framework.common.pojo.CommonResult;
import com.yc.ship.framework.common.util.object.BeanUtils;
import com.yc.ship.module.product.api.dto.SupplierRespDTO;
import com.yc.ship.module.resource.ResourceApi;
import com.yc.ship.module.resource.api.dto.CheckMachineDTO;
import com.yc.ship.module.resource.api.dto.ResourceRouteRespDTO;
import com.yc.ship.module.resource.controller.admin.supplier.vo.SupplierRespVO;
import com.yc.ship.module.resource.dal.dataobject.route.ResourceRouteDO;
import com.yc.ship.module.resource.service.machine.ScenicMachineService;
import com.yc.ship.module.resource.service.route.ResourceRouteService;
import com.yc.ship.module.resource.service.supplier.ProductSupplierService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.List;

import static com.yc.ship.framework.common.pojo.CommonResult.success;

/**
 * @author ：qsl
 * @description：TODO
 * @date ：2025/8/12 09:47
 **/
@Service
public class ResourceApiImpl implements ResourceApi {

    @Resource
    private ProductSupplierService productSupplierService;

    @Resource
    private ScenicMachineService scenicMachineService;

    @Resource
    private ResourceRouteService resourceRouteService;


    @Override
    public CommonResult<SupplierRespDTO> getSupplierById(Long supplierId) {
        SupplierRespVO supplier = productSupplierService.getSupplierById(supplierId);
        return success(BeanUtils.toBean(supplier, SupplierRespDTO.class));
    }
    @Override
    public CommonResult<?> getCheckMachineInfo(Integer siteType,String machineId) {
        Object machineInfo = scenicMachineService.getMachineInfo(siteType,machineId);
        return success(machineInfo);
    }

    @Override
    public CommonResult<?> getAllRouteList() {
        List<ResourceRouteDO> routeList = resourceRouteService.getRouteList();
        return success(BeanUtils.toBean(routeList, ResourceRouteRespDTO.class));
    }

    @Cacheable(cacheNames = "getCheckMachine#30", key = "#type+'_'+#machineId+'_'+#tenantId")
    @Override
    public CommonResult<CheckMachineDTO> getCheckMachine(Integer type, String machineId, Long tenantId) {
        return success(scenicMachineService.getCheckMachine(machineId, type, tenantId));
    }
}