package com.ycwl.basic.controller.printer;

import com.ycwl.basic.annotation.IgnoreToken;
import com.ycwl.basic.model.pc.printer.entity.PrinterEntity;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@IgnoreToken
// 打印机对接接口
@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");
    }

    @PostMapping("/detail")
    public ApiResponse<PrinterEntity> detail(@RequestBody WorkerAuthReqVo req) {
        return ApiResponse.success(printerService.getByAccessKey(req.getAccessKey()));
    }

    @PostMapping("/scenic")
    public ApiResponse scenic(@RequestBody WorkerAuthReqVo req) {
        return ApiResponse.success(printerService.getScenicBasicByAccessKey(req.getAccessKey()));
    }

    @PostMapping("/open")
    public ApiResponse open(@RequestBody WorkerAuthReqVo req) {
        printerService.openPrinter(req.getAccessKey());
        return ApiResponse.success("OK");
    }

    @PostMapping("/close")
    public ApiResponse close(@RequestBody WorkerAuthReqVo req) {
        printerService.closePrinter(req.getAccessKey());
        return ApiResponse.success("OK");
    }
}