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=1740288076380#/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%2Fdoc_analysis_office&method=post
 */
@NoArgsConstructor
@Data
public class BDocAnalysisOfficeResp extends BBaseResp {


    @JsonProperty("underline")
    private List<UnderlineDTO> underline;
    @JsonProperty("formula_result")
    private List<FormulaResultDTO> formulaResult;
    @JsonProperty("layouts")
    private List<LayoutsDTO> layouts;
    @JsonProperty("tables_result")
    private List<TablesResultDTO> tablesResult;
    @JsonProperty("sections")
    private List<SectionsDTO> sections;
    @JsonProperty("layouts_num")
    private Integer layoutsNum;
    @JsonProperty("img_direction")
    private Integer imgDirection;
    @JsonProperty("results")
    private List<ResultsDTO> results;
    @JsonProperty("seal_recog_num")
    private Integer sealRecogNum;
    @JsonProperty("table_num")
    private Integer tableNum;
    @JsonProperty("results_num")
    private Integer resultsNum;
    @JsonProperty("sec_rows")
    private Integer secRows;
    @JsonProperty("sec_cols")
    private Integer secCols;
    @JsonProperty("log_id")
    private String logId;

    @JsonProperty("pdf_file_size")
    private String pdfFileSize;

    @JsonProperty("log_id")
    private String ofdFileSize;


    @JsonProperty("error_msg")
    private String errorMsg;



    @NoArgsConstructor
    @Data
    public static class UnderlineDTO {
        @JsonProperty("prob")
        private Double prob;
        @JsonProperty("points")
        private PointsDTO points;

        @NoArgsConstructor
        @Data
        public static class PointsDTO {
            @JsonProperty("start_x")
            private Double startX;
            @JsonProperty("end_x")
            private Double endX;
            @JsonProperty("end_y")
            private Double endY;
            @JsonProperty("start_y")
            private Double startY;
        }
    }

    @NoArgsConstructor
    @Data
    public static class FormulaResultDTO {
        @JsonProperty("form_words")
        private String formWords;
        @JsonProperty("form_location")
        private FormLocationDTO formLocation;

        @NoArgsConstructor
        @Data
        public static class FormLocationDTO {
            @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 LayoutsDTO {
        @JsonProperty("layout")
        private String layout;
        @JsonProperty("layout_location")
        private List<LayoutLocationDTO> layoutLocation;
        @JsonProperty("layout_prob")
        private Double layoutProb;
        @JsonProperty("layout_idx")
        private List<Integer> layoutIdx;

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

    @NoArgsConstructor
    @Data
    public static class TablesResultDTO {
        @JsonProperty("header")
        private List<HeaderDTO> header;
        @JsonProperty("body")
        private List<BodyDTO> body;
        @JsonProperty("table_location")
        private List<TableLocationDTO> tableLocation;
        @JsonProperty("footer")
        private List<FooterDTO> footer;

        @NoArgsConstructor
        @Data
        public static class HeaderDTO {
            @JsonProperty("location")
            private List<LocationDTO> location;
            @JsonProperty("words")
            private String words;

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

        @NoArgsConstructor
        @Data
        public static class BodyDTO {
            @JsonProperty("cell_location")
            private List<CellLocationDTO> cellLocation;
            @JsonProperty("row_start")
            private Integer rowStart;
            @JsonProperty("contents")
            private List<ContentsDTO> contents;
            @JsonProperty("col_start")
            private Integer colStart;
            @JsonProperty("words")
            private String words;
            @JsonProperty("row_end")
            private Integer rowEnd;
            @JsonProperty("col_end")
            private Integer colEnd;

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

            @NoArgsConstructor
            @Data
            public static class ContentsDTO {
                @JsonProperty("poly_location")
                private List<PolyLocationDTO> polyLocation;
                @JsonProperty("word")
                private String word;

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

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

        @NoArgsConstructor
        @Data
        public static class FooterDTO {
            @JsonProperty("location")
            private List<LocationDTO> location;
            @JsonProperty("words")
            private String words;

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

    @NoArgsConstructor
    @Data
    public static class SectionsDTO {
        @JsonProperty("attribute")
        private String attribute;
        @JsonProperty("sec_idx")
        private SecIdxDTO secIdx;
        @JsonProperty("attri_location")
        private AttriLocationDTO attriLocation;
        @JsonProperty("sections_prob")
        private Double sectionsProb;

        @NoArgsConstructor
        @Data
        public static class SecIdxDTO {
            @JsonProperty("para_idx")
            private List<Integer> paraIdx;
            @JsonProperty("col_idx")
            private List<Integer> colIdx;
            @JsonProperty("row_idx")
            private List<Integer> rowIdx;
            @JsonProperty("idx")
            private List<Integer> idx;
        }

        @NoArgsConstructor
        @Data
        public static class AttriLocationDTO {
            @JsonProperty("points")
            private List<PointsDTO> points;

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

    @NoArgsConstructor
    @Data
    public static class ResultsDTO {
        @JsonProperty("words")
        private WordsDTO words;
        @JsonProperty("words_type")
        private String wordsType;

        @NoArgsConstructor
        @Data
        public static class WordsDTO {
            @JsonProperty("word")
            private String word;
            @JsonProperty("poly_location")
            private List<PolyLocationDTO> polyLocation;
            @JsonProperty("line_probability")
            private LineProbabilityDTO lineProbability;
            @JsonProperty("words_location")
            private WordsLocationDTO wordsLocation;

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

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

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