// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/account/Account.java
// public final class Account implements Serializable {
// 
//     private final Datacenter datacenter;
// 
//     private final String accountCode;
// 
//     /**
//      * Construct an account instance.
//      * @param datacenter the datacenter that hosts the account.
//      * @param accountCode the customer account code.
//      */
//     public Account(Datacenter datacenter, String accountCode) {
//         if (datacenter == null || StringUtils.isBlank(datacenter.getHost()) || StringUtils.isBlank(datacenter.getName())) {
//             throw new IllegalArgumentException("A datacenter name and host must be provided");
//         }
//         if (StringUtils.isBlank(accountCode)) {
//             throw new IllegalArgumentException("An account code must be provided");
//         }
//         this.datacenter = datacenter;
//         this.accountCode = accountCode;
//     }
// 
//     /**
//      * Returns the datacenter
//      * @return the datacenter that hosts the account.
//      */
//     public Datacenter getDatacenter() {
//         return datacenter;
//     }
// 
//     public String getAccountCode() {
//         return accountCode;
//     }
// 
//     @Override
//     public String toString() {
//         return "Account{" +
//                 "datacenter=" + datacenter +
//                 ", accountCode='" + accountCode + '\'' +
//                 '}';
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
//         Account account = (Account) o;
//         if (accountCode != null ? !accountCode.equals(account.accountCode) : account.accountCode != null) return false;
//         if (datacenter != null ? !datacenter.equals(account.datacenter) : account.datacenter != null) return false;
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = datacenter != null ? datacenter.hashCode() : 0;
//         result = 31 * result + (accountCode != null ? accountCode.hashCode() : 0);
//         return result;
//     }
// }
// 
// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/util/StringUtils.java
// public final class StringUtils {
// 
//     private StringUtils() { }
// 
//     public static boolean isEmpty(String string) {
//         return string == null || string.length() == 0;
//     }
// 
//     public static boolean isNotEmpty(String string) {
//         return !isEmpty(string);
//     }
// 
//     public static boolean isBlank(String string) {
//         return string == null || string.trim().length() == 0;
//     }
// 
//     public static boolean isNotBlank(String string) {
//         return !isBlank(string);
//     }
// 
//     public static boolean equals(String lhs, String rhs) {
//         if ((lhs == null) != (rhs == null)) {
//             return false;
//         } else if (lhs == null && rhs == null) {
//             return true;
//         } else {
//             return lhs.equals(rhs);
//         }
//     }
// 
//     public static String join(Collection<String> strings, String separator) {
//         StringBuilder builder = new StringBuilder();
//         for (String string : strings) {
//             if (builder.length() > 0) {
//                 builder.append(separator);
//             }
//             builder.append(string);
//         }
//         return builder.toString();
//     }
// 
// }


import uk.co.visalia.brightpearl.apiclient.account.Account;
import uk.co.visalia.brightpearl.apiclient.util.StringUtils;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/*
 * Copyright 2014 David Morrissey
 *
 * 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 uk.co.visalia.brightpearl.apiclient.auth;



/**
 * Contains the details of a private app, the Brightpearl customer account to which it belongs, and either an account token
 * or a staff token for authorisation of calls to this account.
 */
public final class PrivateAppAuthorisation implements AppAuthorisation {

    private final PrivateAppIdentity appIdentity;

    private final String accountToken;

    private final String staffToken;

    private PrivateAppAuthorisation(PrivateAppIdentity appIdentity, String accountToken, String staffToken) {
        this.appIdentity = appIdentity;
        this.accountToken = accountToken;
        this.staffToken = staffToken;
    }

    /**
     * Create account authorisation details for a private (own account) system-to-system call using the account token
     * generated for a private app.
     * @param appIdentity Details of the private app including the Brightpearl customer account it belongs to.
     * @param accountToken Account token generated for the private app.
     * @return authorisation details.
     */
    public static PrivateAppAuthorisation system(PrivateAppIdentity appIdentity, String accountToken) {
        if (appIdentity == null) { throw new IllegalArgumentException("App identity is required"); }
// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/account/Account.java
// public final class Account implements Serializable {
// 
//     private final Datacenter datacenter;
// 
//     private final String accountCode;
// 
//     /**
//      * Construct an account instance.
//      * @param datacenter the datacenter that hosts the account.
//      * @param accountCode the customer account code.
//      */
//     public Account(Datacenter datacenter, String accountCode) {
//         if (datacenter == null || StringUtils.isBlank(datacenter.getHost()) || StringUtils.isBlank(datacenter.getName())) {
//             throw new IllegalArgumentException("A datacenter name and host must be provided");
//         }
//         if (StringUtils.isBlank(accountCode)) {
//             throw new IllegalArgumentException("An account code must be provided");
//         }
//         this.datacenter = datacenter;
//         this.accountCode = accountCode;
//     }
// 
//     /**
//      * Returns the datacenter
//      * @return the datacenter that hosts the account.
//      */
//     public Datacenter getDatacenter() {
//         return datacenter;
//     }
// 
//     public String getAccountCode() {
//         return accountCode;
//     }
// 
//     @Override
//     public String toString() {
//         return "Account{" +
//                 "datacenter=" + datacenter +
//                 ", accountCode='" + accountCode + '\'' +
//                 '}';
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
//         Account account = (Account) o;
//         if (accountCode != null ? !accountCode.equals(account.accountCode) : account.accountCode != null) return false;
//         if (datacenter != null ? !datacenter.equals(account.datacenter) : account.datacenter != null) return false;
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = datacenter != null ? datacenter.hashCode() : 0;
//         result = 31 * result + (accountCode != null ? accountCode.hashCode() : 0);
//         return result;
//     }
// }
// 
// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/util/StringUtils.java
// public final class StringUtils {
// 
//     private StringUtils() { }
// 
//     public static boolean isEmpty(String string) {
//         return string == null || string.length() == 0;
//     }
// 
//     public static boolean isNotEmpty(String string) {
//         return !isEmpty(string);
//     }
// 
//     public static boolean isBlank(String string) {
//         return string == null || string.trim().length() == 0;
//     }
// 
//     public static boolean isNotBlank(String string) {
//         return !isBlank(string);
//     }
// 
//     public static boolean equals(String lhs, String rhs) {
//         if ((lhs == null) != (rhs == null)) {
//             return false;
//         } else if (lhs == null && rhs == null) {
//             return true;
//         } else {
//             return lhs.equals(rhs);
//         }
//     }
// 
//     public static String join(Collection<String> strings, String separator) {
//         StringBuilder builder = new StringBuilder();
//         for (String string : strings) {
//             if (builder.length() > 0) {
//                 builder.append(separator);
//             }
//             builder.append(string);
//         }
//         return builder.toString();
//     }
// 
// }


// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/auth/PrivateAppAuthorisation.java
import uk.co.visalia.brightpearl.apiclient.account.Account;
import uk.co.visalia.brightpearl.apiclient.util.StringUtils;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/*
 * Copyright 2014 David Morrissey
 *
 * 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 uk.co.visalia.brightpearl.apiclient.auth;



/**
 * Contains the details of a private app, the Brightpearl customer account to which it belongs, and either an account token
 * or a staff token for authorisation of calls to this account.
 */
public final class PrivateAppAuthorisation implements AppAuthorisation {

    private final PrivateAppIdentity appIdentity;

    private final String accountToken;

    private final String staffToken;

    private PrivateAppAuthorisation(PrivateAppIdentity appIdentity, String accountToken, String staffToken) {
        this.appIdentity = appIdentity;
        this.accountToken = accountToken;
        this.staffToken = staffToken;
    }

    /**
     * Create account authorisation details for a private (own account) system-to-system call using the account token
     * generated for a private app.
     * @param appIdentity Details of the private app including the Brightpearl customer account it belongs to.
     * @param accountToken Account token generated for the private app.
     * @return authorisation details.
     */
    public static PrivateAppAuthorisation system(PrivateAppIdentity appIdentity, String accountToken) {
        if (appIdentity == null) { throw new IllegalArgumentException("App identity is required"); }
        if (StringUtils.isBlank(accountToken)) { throw new IllegalArgumentException("Account token is required"); }