package com.prolog.eis.controller.pda;

import com.prolog.eis.core.model.biz.route.ContainerLocation;
import com.prolog.eis.model.container.LocationCfg;
import com.prolog.eis.service.container.LocationCfgService;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.fx.inf.core.InterfaceType;
import com.prolog.fx.inf.core.annotation.InterfaceMethod;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/location")
public class LocationController {

    private final LocationCfgService locationService;

    @ApiOperation(value = "通过容器号查询位置信息", notes = "通过容器号查询位置信息")
    @PostMapping(value = "/find/location/byContainer")
    @InterfaceMethod(key = "findLocationByContainer", name = "通过容器号查询位置信息(WMS->EIS)", type = InterfaceType.Receive)
    public RestMessage findLocationByContainer(@RequestBody ContainerLocation containerLocation) {
        try {
            ContainerLocation containerLocationRespDto = locationService.findLocationByContainer(containerLocation);
            return RestMessage.newInstance(true, "请求成功", containerLocationRespDto);
        } catch (Exception e) {
            log.error("通过容器号查询位置信息异常:{}", e);
            return RestMessage.newInstance(false, "请求异常" + e.getMessage());
        }
    }

    @ApiOperation(value = "查询可指定托盘出的区域", notes = "查询可指定托盘出的区域")
    @GetMapping(value = "/find/available/area")
    @InterfaceMethod(key = "findAvailableArea", name = "查询可指定托盘出的区域(WMS->EIS)", type = InterfaceType.Receive)
    public RestMessage findAvailableArea(){
        try {
            List<String> list = locationService.findAvailableArea();
            return RestMessage.newInstance(true, "请求成功", list);

        }catch (Exception e){
            log.error("查询可指定托盘出的区域信息异常：{}",e);
            return RestMessage.newInstance(false,"请求异常" + e.getMessage());
        }
    }

    @ApiOperation(value = "通过区域找点位", notes = "通过区域找点位")
    @GetMapping(value = "/find/point/Byarea")
    @InterfaceMethod(key = "findLocationByarea", name = "通过区域找点位(WMS->EIS)", type = InterfaceType.Receive)
    public RestMessage findLocationByarea(@RequestParam("area") String area){
        try {
            List<LocationCfg> list = locationService.findLocationByarea(area);
            return RestMessage.newInstance(true,"请求成功",list);
        }catch (Exception e){
            log.error("通过区域找点位信息异常：{}",e);
            return RestMessage.newInstance(false,"请求异常" + e.getMessage());
        }
    }



}
