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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.heyu.api.baidu.response.BBaseResp;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * https://console.bce.baidu.com/support/?_=1740219852952&timestamp=1740294887952#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E9%80%9A%E7%94%A8%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Fwebimage_loc&method=post
 *
 * 网络图片文字识别（含位置版）
 */
@NoArgsConstructor
@Data
public class BWebImageLocResp extends BBaseResp {


    @JsonProperty("words_result")
    private List<WordsResultDTO> wordsResult;
    @JsonProperty("direction")
    private Integer direction;
    @JsonProperty("words_result_num")
    private Integer wordsResultNum;
    @JsonProperty("log_id")
    private String logId;

    @NoArgsConstructor
    @Data
    public static class WordsResultDTO {
        @JsonProperty("chars")
        private List<CharsDTO> chars;
        @JsonProperty("probability")
        private ProbabilityDTO probability;
        @JsonProperty("location")
        private LocationDTO location;
        @JsonProperty("poly_location")
        private List<PolyLocationDTO> polyLocation;
        @JsonProperty("words")
        private String words;

        @NoArgsConstructor
        @Data
        public static class ProbabilityDTO {
            @JsonProperty("average")
            private Double average;
            @JsonProperty("min")
            private Double min;
            @JsonProperty("variance")
            private Integer variance;
        }

        @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;
        }

        @NoArgsConstructor
        @Data
        public static class CharsDTO {
            @JsonProperty("char")
            private String charX;
            @JsonProperty("location")
            private LocationDTO location;

            @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;
            }
        }

        @NoArgsConstructor
        @Data
        public static class PolyLocationDTO {
            @JsonProperty("x")
            private Integer x;
            @JsonProperty("y")
            private Integer y;
        }
    }
}
