// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.api;

import com.yahoo.athenz.auth.token.RoleToken;
import com.yahoo.vespa.athenz.utils.AthenzIdentities;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;

/**
 * Represents an Athenz ZToken (role token)
 *
 * @author bjorncs
 */
public class ZToken {

    private final RoleToken token;

    public ZToken(String rawToken) {
        this.token = new RoleToken(rawToken);
    }

    public String getRawToken() {
        return token.getSignedToken();
    }

    public AthenzIdentity getIdentity() {
        return AthenzIdentities.from(token.getPrincipal());
    }

    public List<AthenzRole> getRoles() {
        String domain = token.getDomain();
        return token.getRoles().stream()
                .map(roleName -> new AthenzRole(domain, roleName))
                .collect(toList());}

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

    @Override
    public int hashCode() {
        return Objects.hash(getRawToken());
    }


}

@@ -302,44 +302,8 @@
 cts;
-%0Aimport java.util.stream.Collectors;
 %0A%0Aim
@@ -755,32 +755,129 @@
 ipal());%0A    %7D%0A%0A
+    public AthenzDomain getDomain() %7B%0A        return new AthenzDomain(token.getDomain());%0A    %7D%0A%0A
     public List%3C

Add getter for role token domain