package com.usky.ai.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;

import java.util.List;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class AlgAbilityFetchResponseDTO {
    @JsonProperty("BoardId")
    private String boardId;

    @JsonProperty("BoardIp")
    private String boardIp;

    @JsonProperty("Ability")
    private List<Algorithm> ability;

    @JsonProperty("Result")
    private Result result;

    private long time = System.currentTimeMillis();

    public boolean isSuccess() {
        return result != null && Integer.valueOf(0).equals(result.getCode());
    }

    @Data
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Algorithm {
        @JsonProperty("attribute")
        private JsonNode attribute;

        @JsonProperty("parameters")
        private List<Parameter> parameters;

        @JsonProperty("permitted")
        private boolean permitted;

        @JsonProperty("code")
        private int code;

        @JsonProperty("sub")
        private boolean sub;

        @JsonProperty("name")
        private String name;

        @JsonProperty("desc")
        private String desc;

        @JsonProperty("item")
        private int item;

        @JsonProperty("policy")
        private List<Policy> policy;

        @Data
        @JsonIgnoreProperties(ignoreUnknown = true)
        public static class Parameter {
            @JsonProperty("class")
            private String classType;

            @JsonProperty("type")
            private int type;

            @JsonProperty("max")
            private Object max;

            @JsonProperty("min")
            private Object min;

            @JsonProperty("default")
            private Object defaultValue;

            @JsonProperty("key")
            private String key;

            @JsonProperty("name")
            private String name;

            @JsonProperty("required")
            private boolean required;

            @JsonProperty("value")
            private Object value;

            @JsonProperty("options")
            private List<Option> options;

            @Data
            @JsonIgnoreProperties(ignoreUnknown = true)
            public static class Option {
                @JsonProperty("enable")
                private boolean enable;

                @JsonProperty("key")
                private String key;

                @JsonProperty("value")
                private int value;

                @JsonProperty("name")
                private String name;
            }
        }

        @Data
        @JsonIgnoreProperties(ignoreUnknown = true)
        public static class Policy {
            @JsonProperty("property")
            private String property;

            @JsonProperty("name")
            private String name;
        }
    }

    @Data
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Result {
        @JsonProperty("Code")
        private int code;

        @JsonProperty("Desc")
        private String desc;
    }
}
