package com.tmerclub.cloud.warehouse.controller.app;

import cn.hutool.core.util.ObjectUtil;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.warehouse.model.vo.WarehouseVO;
import com.tmerclub.cloud.warehouse.service.WarehouseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * app-仓库
 *
 * @author : frank
 * @create : 2025-04-14
 */
@Tag(name = "app-仓库")
@RestController("appWarehouseController")
@RequestMapping("/app/warehouse")
public class WarehouseController {
    @Resource
    WarehouseService warehouseService;

    /**
     * 根据经纬度获取最近的仓库信息
     *
     * @param lat 纬度
     * @param lng 经度
     * @return 最近的仓库信息
     */
    @GetMapping("/getNearbyWarehouse")
    public ServerResponseEntity<WarehouseVO> getNearbyWarehouse(@RequestParam("orderId") Long orderId, @RequestParam("lat") BigDecimal lat, @RequestParam("lng") BigDecimal lng) {
        WarehouseVO nearbyWarehouse = warehouseService.getNearbyWarehouse(orderId, lat, lng);
        return ServerResponseEntity.success(nearbyWarehouse);
    }

    /**
     * 根据id查询仓库信息
     *
     * @param warehouseId 仓库id
     * @return 仓库信息
     */
    @GetMapping("/getWarehouseById")
    @Operation(summary = "根据id查询仓库信息", description = "根据id查询仓库信息")
    public ServerResponseEntity<WarehouseVO> getById(@RequestParam("warehouseId") Long warehouseId) {
        WarehouseVO warehouseVO = warehouseService.getById(warehouseId);
        if (ObjectUtil.isNull(warehouseVO)) {
            return ServerResponseEntity.showFailMsg("暂无仓库信息");
        }
        return ServerResponseEntity.success(warehouseVO);
    }
}