package com.youchain.businessdata.rest;

import com.youchain.annotation.AnonymousAccess;
import com.youchain.annotation.Log;
import com.youchain.appupdate.inputJson.MissionStateCallback;
import com.youchain.businessdata.domain.AgvTask;
import com.youchain.businessdata.domain.ItemKey;
import com.youchain.businessdata.domain.Task;
import com.youchain.businessdata.inputJson.ReturnIssueInfo;
import com.youchain.businessdata.inputJson.ReturnIssueInfoParams;
import com.youchain.businessdata.inputJson.ReturnMoInfo;
import com.youchain.businessdata.inputJson.ReturnMoParams;
import com.youchain.businessdata.repository.AgvTaskRepository;
import com.youchain.businessdata.repository.InventoryRepository;
import com.youchain.businessdata.repository.TaskRepository;
import com.youchain.businessdata.service.AgvTaskService;
import com.youchain.businessdata.service.MlsService;
import com.youchain.businessdata.service.OrderService;
import com.youchain.businessdata.service.TaskService;
import com.youchain.businessdata.service.dto.AgvTaskDto;
import com.youchain.businessdata.service.dto.OrderDto;
import com.youchain.exception.handler.ApiResult;
import com.youchain.service.LogService;
import com.youchain.utils.BizStatus;
import com.youchain.utils.UrlApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;


@RestController
@RequiredArgsConstructor
@Api(tags = "KMReS")
@RequestMapping("/api/amr")
@Slf4j
public class KMReSAgvTaskController {

    private final KMReSController kmReSController;
    private final AgvTaskRepository agvTaskRepository;

    @PostMapping("/cancelAgvTasks")
    @Log("取消搬运任务")
    @ApiOperation("取消搬运任务")
    @AnonymousAccess
    public ResponseEntity<Object> closeAgvTask(@RequestBody Long id) {
        AgvTask agvTask=agvTaskRepository.getById(Math.toIntExact(id));
        MissionStateCallback missionStateCallback=new MissionStateCallback();
        missionStateCallback.setMissionStatus(BizStatus.CANCEL);
        missionStateCallback.setMissionCode(agvTask.getJobForce());
        missionStateCallback.setContainerCode(agvTask.getStockCode());
        kmReSController.missionStateCallbackChild(missionStateCallback);
        return new ResponseEntity<>(ApiResult.fail(200, "操作成功", null),HttpStatus.OK);
    }
    @PostMapping("/pickerSendAgvTasks")
    @Log("完成搬运任务")
    @ApiOperation("完成搬运任务")
    @AnonymousAccess
    public ResponseEntity<Object> pickerSendAgvTask(@RequestBody Long id) {
        AgvTask agvTask=agvTaskRepository.getById(Math.toIntExact(id));
        MissionStateCallback missionStateCallback=new MissionStateCallback();
        missionStateCallback.setMissionStatus(BizStatus.PICKER_SEND);
        missionStateCallback.setMissionCode(agvTask.getJobForce());
        missionStateCallback.setContainerCode(agvTask.getStockCode());
        missionStateCallback.setSlotCode(agvTask.getEndSlotCode());
        kmReSController.missionStateCallbackChild(missionStateCallback);
        return new ResponseEntity<>(ApiResult.fail(200, "操作成功", null),HttpStatus.OK);
    }
}
