package com.usky.ai.dto;

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

import java.util.List;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class EdgeAlgTaskListResponseDTO {

    @JsonProperty("BoardId")
    private String boardId;

    @JsonProperty("BoardIp")
    private String boardIp;

    @JsonProperty("Content")
    private List<TaskItem> content;

    @JsonProperty("Event")
    private String event;

    @JsonProperty("Result")
    private Result result;

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


    @Data
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class TaskItem {
        @JsonProperty("AlgTaskSession")
        private String algTaskSession;

        @JsonProperty("MediaName")
        private String mediaName;

        @JsonProperty("AlgTaskStatus")
        private AlgTaskStatus algTaskStatus;

        @JsonProperty("AlarmBody")
        private Integer alarmBody;

        @JsonProperty("AlarmProtocol")
        private Integer alarmProtocol;

        @JsonProperty("MetadataUrl")
        private String metadataUrl;

        @JsonProperty("TaskDesc")
        private String taskDesc;

        @JsonProperty("UserData")
        private UserData userData;

        @JsonProperty("AlgInfo")
        private List<Integer> algInfo;

        @JsonProperty("GB28181Channel")
        private String gb28181Channel;

        @JsonProperty("Template")
        private String template;

        @JsonProperty("Restart")
        private Boolean restart;

        @JsonProperty("RuleProperty")
        private List<RuleProperty> ruleProperty;

        @JsonProperty("BaseAlgItem")
        private List<BaseAlgItem> baseAlgItem;
    }

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

        @JsonProperty("style")
        private String style;

        @JsonProperty("type")
        private Integer type;
    }

    @Data
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class UserData {
        @JsonProperty("MethodConfig")
        private List<Integer> methodConfig;
    }

    @Data
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class RuleProperty {
        @JsonProperty("RuleId")
        private String ruleId;

        @JsonProperty("RuleType")
        private Integer ruleType;

        @JsonProperty("RuleTypeName")
        private String ruleTypeName;

        @JsonProperty("Algo")
        private Algo algo;

        @JsonProperty("Points")
        private List<Point> points;

        @Data
        @JsonIgnoreProperties(ignoreUnknown = true)
        public static class Algo {
            @JsonProperty("majorId")
            private Integer majorId;

            @JsonProperty("minorId")
            private Integer minorId;
        }

        @Data
        @JsonIgnoreProperties(ignoreUnknown = true)
        public static class Point {
            @JsonProperty("X")
            private Double x;

            @JsonProperty("Y")
            private Double y;
        }
    }

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

        @JsonProperty("lineRequired")
        private Boolean lineRequired;

        @JsonProperty("majorId")
        private Integer majorId;

        @JsonProperty("majorOnly")
        private Boolean majorOnly;

        @JsonProperty("minorId")
        private Integer minorId;

        @JsonProperty("name")
        private String name;

        @JsonProperty("zoneDesc")
        private String zoneDesc;

        @JsonProperty("zoneRequired")
        private Boolean zoneRequired;
    }

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

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

    private long time = System.currentTimeMillis();
}