package com.mortals.xhx.busiz.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.busiz.req.ApiReqPdu;
import com.mortals.xhx.busiz.req.PrintReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.IdCardResp;
import com.mortals.xhx.busiz.rsp.PrintListResp;
import com.mortals.xhx.busiz.rsp.PrintQueueResp;
import com.mortals.xhx.common.code.BusizTypeEnum;
import com.mortals.xhx.module.idCard.model.IdCardCons;
import com.mortals.xhx.module.idCard.service.IdCardService;
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.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * api controller
 *
 * @author: zxfei
 * @date: 2022/12/26 10:21
 */
@RestController
@Slf4j
public class ApiController extends BaseAbstractApiController {

    @Autowired
    private PrintService printService;
    @Autowired
    private IdCardService idCardService;

    @RequestMapping(value = "GetHardWareInfo", method = {RequestMethod.POST, RequestMethod.GET})
    public Object GetHardWareInfo(@RequestParam Map<String, Object> reqMap) {
        String getType = (String) reqMap.getOrDefault("GetType", "");
        String reqJson = (String) reqMap.getOrDefault("PrinterJson", "");
        String printerName = (String) reqMap.getOrDefault("printerName", "");
        log.info("req==>getType:{},body=>{}", getType, JSON.toJSONString(reqMap));
        try {
            switch (BusizTypeEnum.getByValue(getType)) {
                case BUSIZ_ASSESSMENT:
                    ApiResp<Object> assessResp = handle(JSON.toJSONString(reqMap), "busizAssessmentReqHandler");
                    return assessResp;
                case BUSIZ_PRINT:
                    ApiResp<Object> rest = handle(JSON.parseObject(reqJson, PrintReq.class), "busizPrintReqHandler");
                    return rest;
                case BUSIZ_PRINTLIST:
                    //获取打印机列表
                    ApiResp<Object> printListResp = handle("", "busizPrintListReqHandler");
                    return printListResp;
                case BUSIZ_PRINT_QUEUE:
                    ApiResp<Object> printQueueResp = handle(printerName, "busizPrintQueueReqHandler");
                    return printQueueResp;
                case BUSIZ_IDCARD_RECOGNITION:
                    ApiResp<Object> idCardResp = handle("", "busizIdcardRecognitionReqHandler");
                    return idCardResp;
                case BUSIZ_CAPTURE:
                    ApiResp<Object> captureResp = handle("", "busizCaptureReqHandler");
                    return captureResp;
            }
        } catch (Exception e) {
            log.error("接收数据失败", e);
            return ApiResp.fail(e.getMessage());
        }
        return ApiResp.ok();
    }
}
