package com.heyu.api.baidu.response.common;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.heyu.api.baidu.response.BBaseResp;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;


/**
 * {
 * "codes_result": [
 * {
 * "location": {
 * "top": 54,
 * "left": 62,
 * "width": 296,
 * "height": 304
 * },
 * "text": [
 * "eewewwe"
 * ],
 * "type": "QR_CODE"
 * }
 * ],
 * "codes_result_num": 1,
 * "log_id": "1893581589682345139"
 * }
 */
@Data
@Slf4j
@NoArgsConstructor
public class BQrcodeReconizeResp extends BBaseResp {


    @JsonProperty("codes_result")
    private List<CodesResultDTO> codesResult;

    @JsonProperty("codes_result_num")
    private Integer codesResultNum;
    @JsonProperty("log_id")
    private String logId;


    @NoArgsConstructor
    @Data
    public static class CodesResultDTO {
        /**
         * 识别码类型条码类型包括：9种条形码（UPC_A、UPC_E、EAN_13、EAN_8、CODE_39、CODE_93、CODE_128、ITF、CODABAR），4种二维码（QR_CODE、DATA_MATRIX、AZTEC、PDF_417）
         */
        @JsonProperty("type")
        private String type;

        @JsonProperty("location")
        private LocationDTO location;

        @JsonProperty("text")
        private List<String> text;


        @NoArgsConstructor
        @Data
        public static class LocationDTO {
            @JsonProperty("top")
            private Integer top;
            @JsonProperty("left")
            private Integer left;
            @JsonProperty("width")
            private Integer width;
            @JsonProperty("height")
            private Integer height;
        }
    }


    public static void main(String[] args) {
        String a= "{\n" +
                "    \"codes_result\": [\n" +
                "        {\n" +
                "            \"location\": {\n" +
                "                \"top\": 54,\n" +
                "                \"left\": 62,\n" +
                "                \"width\": 296,\n" +
                "                \"height\": 304\n" +
                "            },\n" +
                "            \"text\": [\n" +
                "                \"eewewwe\"\n" +
                "            ],\n" +
                "            \"type\": \"QR_CODE\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"codes_result_num\": 1,\n" +
                "    \"log_id\": \"1893581589682345139\"\n" +
                "}";
        BQrcodeReconizeResp codesResultDTO = JSONObject.parseObject(a, BQrcodeReconizeResp.class);
        System.out.println(JSON.toJSONString(codesResultDTO));
    }

}

