// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.configserver.noderepository.bindings;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Collections;
import java.util.List;

/**
 * This class represents a response from the /nodes/v2/acl/ API.
 *
 * @author mpolden
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class GetAclResponse {

    @JsonProperty("trustedNodes")
    public final List<Node> trustedNodes;

    @JsonProperty("trustedNetworks")
    public final List<Network> trustedNetworks;

    @JsonCreator
    public GetAclResponse(@JsonProperty("trustedNodes") List<Node> trustedNodes,
                          @JsonProperty("trustedNetworks") List<Network> trustedNetworks) {
        this.trustedNodes = trustedNodes == null ? Collections.emptyList() : trustedNodes;
        this.trustedNetworks = trustedNetworks == null ? Collections.emptyList() : trustedNetworks;
    }

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Node {

        @JsonProperty("hostname")
        public final String hostname;

        @JsonProperty("ipAddress")
        public final String ipAddress;

        @JsonProperty("trustedBy")
        public final String trustedBy;

        @JsonCreator
        public Node(@JsonProperty("hostname") String hostname, @JsonProperty("ipAddress") String ipAddress,
                    @JsonProperty("trustedBy") String trustedBy) {
            this.hostname = hostname;
            this.ipAddress = ipAddress;
            this.trustedBy = trustedBy;
        }
    }

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Network {

        @JsonProperty("network")
        public final String network;

        @JsonProperty("trustedBy")
        public final String trustedBy;

        @JsonCreator
        public Network(@JsonProperty("network") String network, @JsonProperty("trustedBy") String trustedBy) {
            this.network = network;
            this.trustedBy = trustedBy;
        }
    }
}

@@ -746,24 +746,101 @@
 dNetworks;%0A%0A
+    @JsonProperty(%22trustedPorts%22)%0A    public final List%3CPort%3E trustedPorts;%0A%0A
     @JsonCre
@@ -1013,16 +1013,97 @@
 Networks
+,%0A                          @JsonProperty(%22trustedPorts%22) List%3CPort%3E trustedPorts
 ) %7B%0A    
@@ -1289,16 +1289,107 @@
 tworks;%0A
+        this.trustedPorts = trustedPorts == null ? Collections.emptyList() : trustedPorts;%0A
     %7D%0A%0A 
@@ -2009,24 +2009,104 @@
 y;%0A        %7D
+%0A%0A        public String getTrustedBy() %7B%0A            return trustedBy;%0A        %7D
 %0A    %7D%0A%0A    
@@ -2543,21 +2543,613 @@
 y;%0A        %7D
+%0A%0A        public String getTrustedBy() %7B%0A            return trustedBy;%0A        %7D%0A    %7D%0A%0A    @JsonIgnoreProperties(ignoreUnknown = true)%0A    public static class Port %7B%0A%0A        @JsonProperty(%22port%22)%0A        public final Integer port;%0A%0A        @JsonProperty(%22trustedBy%22)%0A        public final String trustedBy;%0A%0A        @JsonCreator%0A        public Port(@JsonProperty(%22port%22) Integer port, @JsonProperty(%22trustedBy%22) String trustedBy) %7B%0A            this.port = port;%0A            this.trustedBy = trustedBy;%0A        %7D%0A%0A        public String getTrustedBy() %7B%0A            return trustedBy;%0A        %7D
 %0A    %7D%0A%7D%0A

Update response with new data from the acl api