package com.neusoft.smart.pos.printer.controller;

import com.neusoft.smart.pos.dto.printer.request.PostPrinterOrderRequest;
import com.neusoft.smart.pos.dto.printer.request.PostPrinterRequest;
import com.neusoft.smart.pos.dto.printer.request.PrinterQueryRequest;
import com.neusoft.smart.pos.dto.printer.request.PutPrinterRequest;
import com.neusoft.smart.pos.dto.printer.response.GetPrinterResponse;
import com.neusoft.smart.pos.dto.printer.response.PostPrinterOrderResponse;
import com.neusoft.smart.pos.dto.printer.response.PostPrinterQueryResponse;
import com.neusoft.smart.pos.framework.bean.PaginationExtendBean;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.printer.service.PrinterService;
import com.neusoft.smart.pos.printer.service.PrinterServiceOther;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = "打印服务使用rest接口", description = "打印服务使用rest接口")
@RestController
@RequestMapping(path = "/printer")
@Validated
public class PrinterController {
    
    @Autowired
    private PrinterService printerService;
    
    @Autowired
    private PrinterServiceOther printerServiceOther;
    
    
    @ApiOperation(value = "分页查询打印机/中转设备接口", notes = "分页查询打印机")
    @PostMapping("/printers")
    public ResponseData<PaginationExtendBean<PostPrinterQueryResponse>> list(@RequestBody PrinterQueryRequest printerQueryRequest) {
        PaginationExtendBean<PostPrinterQueryResponse> paginationExtendBean = new PaginationExtendBean<>();
        paginationExtendBean.setRows(printerServiceOther.queryPrinterList(printerQueryRequest));
        paginationExtendBean.setTotal(printerServiceOther.queryPinterCount(printerQueryRequest));
        return new ResponseData<>(paginationExtendBean);
    }
    
    @ApiOperation(value = "订单打印使用接口", notes = "订单打印使用方法")
    @PostMapping("/printerOrder")
    public ResponseData<PostPrinterOrderResponse> printerOrder(@RequestBody PostPrinterOrderRequest printerOrderRequest) {
        return new ResponseData<>(printerService.printerOrder(printerOrderRequest));
    }
    
    @ApiOperation(value = "保存打印机或者中转设备接口", notes = "保存打印机或者中转设备接口")
    @PostMapping("/print")
    public ResponseData<?> create(@RequestBody PostPrinterRequest postPrinterRequest) {
        printerServiceOther.create(postPrinterRequest);
        return new ResponseData<>();
    }
    
    @ApiOperation(value = "修改打印机或者中转设备接口", notes = "修改打印机或者中转设备接口")
    @PutMapping("/print")
    public ResponseData<?> update(@RequestBody PutPrinterRequest putPrinterRequest) {
        printerServiceOther.update(putPrinterRequest);
        return new ResponseData<>();
    }
    
    @ApiOperation(value = "修改打印机或者中转设备状态接口", notes = "修改打印机或者中转设备状态接口")
    @PutMapping("/print/status/{printerId}/{status}")
    public ResponseData<?> update(@PathVariable("printerId") Long printerId, @PathVariable("status") String status) {
        printerServiceOther.changeStatus(printerId, status);
        return new ResponseData<>();
    }
    
    @ApiOperation(value = "获取门店下所有打印集合接口", notes = "获取门店下所有打印集合接口")
    @GetMapping("/prints/{shopId}")
    public ResponseData<?> prints(@PathVariable("shopId") Integer shopId) {
        return new ResponseData<>(printerServiceOther.getList(shopId));
    }
    
    @ApiOperation(value = "获取打印集合接口", notes = "获取打印集合接口")
    @GetMapping("/print/{sn}/{peekCount}")
    public ResponseData<?> print(@PathVariable("sn") String sn, @PathVariable("peekCount") Integer peekCount) {
        return new ResponseData<>(printerService.pollTasks(sn, peekCount));
    }
    
    @ApiOperation(value = "标记打印任务完成接口", notes = "标记打印任务完成接口")
    @PutMapping("/print/{printerId}/{taskId}")
    public ResponseData<?> print(@PathVariable("printerId") Integer printerId, @PathVariable("taskId") Integer taskId) {
        printerService.setTaskPrinted(printerId, taskId);
        return new ResponseData<>();
    }
    
    @ApiOperation(value = "获取中转设备连接的打印集合接口", notes = "获取中转设备连接的打印集合接口")
    @GetMapping("/linkedPrinters/{sn}")
    public ResponseData<?> print(@PathVariable("sn") String sn) {
        return new ResponseData<>(printerService.getLinkedPrinters(sn));
    }
    
    
    @ApiOperation(value = "获取中转设备连接的打印集合接口", notes = "获取中转设备连接的打印集合接口")
    @GetMapping("/printer/{id}")
    public ResponseData<?> get(@PathVariable("id") Long id) {
        return new ResponseData<>(printerServiceOther.get(id));
    }
    
    @ApiOperation(value = "打印机详情查询使用接口", notes = "打印机详情查询使用接口")
    @GetMapping("/printer")
    public ResponseData<GetPrinterResponse> queryPrinterDetail(@RequestParam(value="printerId") Long printerId) {
        return new ResponseData<>(printerService.queryPrinterDetail(printerId));
    }
}
	