/*
 * Copyright 2017 flow.ci
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flow.platform.domain;

import com.google.common.base.Strings;

/**
 * Agent path in zookeeper
 *
 * @author gy@fir.im
 */
public class AgentPath extends Jsonable {

    private final static String RESERVED_CHAR = "#";

    private String zone;

    private String name;

    public AgentPath(String zone, String name) {
        if (zone != null && zone.contains(RESERVED_CHAR)) {
            throw new IllegalArgumentException("Agent key not valid");
        }

        // name is nullable
        if (name != null && name.contains(RESERVED_CHAR)) {
            throw new IllegalArgumentException("Agent key not valid");
        }

        this.zone = zone;
        this.name = name;
    }

    public AgentPath() {
    }

    public void setZone(String zone) {
        this.zone = zone;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getZone() {
        return zone;
    }

    public String getName() {
        return name;
    }

    /**
     * Is empty zone and name
     */
    public boolean isEmpty() {
        return Strings.isNullOrEmpty(zone) || Strings.isNullOrEmpty(name);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        AgentPath agentPath = (AgentPath) o;

        if (!zone.equals(agentPath.zone)) {
            return false;
        }
        return name != null ? name.equals(agentPath.name) : agentPath.name == null;
    }

    @Override
    public int hashCode() {
        int result = zone.hashCode();
        result = 31 * result + (name != null ? name.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return String.format("%s#%s", zone, name);
    }
}

@@ -657,16 +657,59 @@
 Strings;
+%0Aimport com.google.gson.annotations.Expose;
 %0A%0A/**%0A *
@@ -858,16 +858,28 @@
 = %22#%22;%0A%0A
+    @Expose%0A
     priv
@@ -892,24 +892,36 @@
 ring zone;%0A%0A
+    @Expose%0A
     private 

fix agent path not exported via json