package com.ycwl.basic.controller.printer;

import com.ycwl.basic.annotation.IgnoreToken;
import com.ycwl.basic.model.printer.req.PrinterSyncReq;
import com.ycwl.basic.model.printer.req.WorkerAuthReqVo;
import com.ycwl.basic.model.printer.resp.PrintTaskResp;
import com.ycwl.basic.model.printer.resp.TaskSyncResp;
import com.ycwl.basic.service.printer.PrinterService;
import com.ycwl.basic.utils.ApiResponse;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@IgnoreToken
@Api(tags = "打印机对接接口")
@RestController
@RequestMapping("/printer/v1")
public class PrinterTaskController {
    @Autowired
    private PrinterService printerService;

    @PostMapping("/sync")
    public ApiResponse<TaskSyncResp> sync(@RequestBody PrinterSyncReq req) {
        List<PrintTaskResp> tasks = printerService.sync(req);
        TaskSyncResp resp = new TaskSyncResp();
        resp.setTasks(tasks);
        return ApiResponse.success(resp);
    }


    @PostMapping("/{taskId}/success")
    public ApiResponse taskSuccess(@PathVariable Integer taskId, @RequestBody WorkerAuthReqVo req) {
        printerService.taskSuccess(taskId, req);
        return ApiResponse.success("OK");
    }

    @PostMapping("/{taskId}/fail")
    public ApiResponse taskFail(@PathVariable Integer taskId, @RequestBody WorkerAuthReqVo req) {
        printerService.taskFail(taskId, req);
        return ApiResponse.success("OK");
    }
}