package com.mortals.xhx.busiz.handler.impl;

import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.handler.BaseReqHandler;
import com.mortals.xhx.busiz.req.PrintReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.PrintListResp;
import com.mortals.xhx.busiz.rsp.PrintQueueResp;
import com.mortals.xhx.module.print.model.Printer;
import com.mortals.xhx.module.print.model.PrinterQueue;
import com.mortals.xhx.module.print.service.PrintService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 打印机列表
 *
 * @author:
 * @date: 2023/1/5 22:25
 */
@Service
@Slf4j
public class BusizPrintListReqHandler extends BaseReqHandler<String, Void> {

    @Autowired
    private PrintService printService;

    @Override
    protected ApiResp<Void> handle(String printerName) throws AppException {
        log.info("【打印机队列查询】【请求体】-->{}", printerName);
        Rest<List<PrinterQueue>> rest = printService.getPrintQueue(printerName);
        PrintQueueResp printQueueResp = new PrintQueueResp();
        printQueueResp.setStatus(PrintListResp.SUCCESS);
        printQueueResp.setMessage("success");
        printQueueResp.setQueueList(rest.getData());
        printQueueResp.setQueueNum(rest.getData().size() + "");
        log.info("【打印列表】【执行响应】-->{}", JSON.toJSONString(printQueueResp));
        return printQueueResp;
    }

    @Override
    protected void validData(String request) throws IllegalArgumentException {

    }


}
