001/*
002 *   Copyright 2024 Vonage
003 *
004 *   Licensed under the Apache License, Version 2.0 (the "License");
005 *   you may not use this file except in compliance with the License.
006 *   You may obtain a copy of the License at
007 *
008 *        http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *   Unless required by applicable law or agreed to in writing, software
011 *   distributed under the License is distributed on an "AS IS" BASIS,
012 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *   See the License for the specific language governing permissions and
014 *   limitations under the License.
015 */
016package com.vonage.client.subaccounts;
017
018import com.fasterxml.jackson.annotation.JsonIgnore;
019import com.fasterxml.jackson.annotation.JsonProperty;
020import com.vonage.client.JsonableBaseObject;
021
022public class UpdateSubaccountRequest extends JsonableBaseObject {
023        @JsonIgnore final String subaccountApiKey;
024        private final String name;
025        private final Boolean usePrimaryAccountBalance, suspended;
026
027        UpdateSubaccountRequest(Builder builder) {
028                subaccountApiKey = AbstractTransfer.validateAccountKey(builder.subaccountApiKey, "Subaccount");
029                usePrimaryAccountBalance = builder.usePrimaryAccountBalance;
030                suspended = builder.suspended;
031                if ((name = builder.name) != null && (name.length() > 80 || name.trim().isEmpty())) {
032                        throw new IllegalArgumentException("Name must be between 1 and 80 characters long.");
033                }
034                if (name == null && usePrimaryAccountBalance == null && suspended == null) {
035                        throw new IllegalStateException("At least one property must be set for updating.");
036                }
037        }
038
039        /**
040         * (OPTIONAL) Name of the subaccount.
041         * 
042         * @return The updated subaccount name, or {@code null} if not set (the default).
043         */
044        @JsonProperty("name")
045        public String getName() {
046                return name;
047        }
048
049        /**
050         * (OPTIONAL) Whether to use the primary account's balance.
051         * 
052         * @return {@code true} if the balance is shared with the primary account or {@code null} if not set (the default).
053         */
054        @JsonProperty("use_primary_account_balance")
055        public Boolean getUsePrimaryAccountBalance() {
056                return usePrimaryAccountBalance;
057        }
058
059        /**
060         * (OPTIONAL) Whether to suspend this subaccount.
061         * 
062         * @return Whether this subaccount should be suspended, or {@code null} if not set (the default).
063         */
064        @JsonProperty("suspended")
065        public Boolean getSuspended() {
066                return suspended;
067        }
068        
069        /**
070         * Entry point for constructing an instance of this class.
071         *
072         * @param subaccountApiKey (REQUIRED) The subaccount's API key.
073         * 
074         * @return A new Builder.
075         */
076        public static Builder builder(String subaccountApiKey) {
077                return new Builder(subaccountApiKey);
078        }
079        
080        public static class Builder {
081                private final String subaccountApiKey;
082                private String name;
083                private Boolean usePrimaryAccountBalance, suspended;
084        
085                Builder(String subaccountApiKey) {
086                        this.subaccountApiKey = subaccountApiKey;
087                }
088
089                /**
090                 * (OPTIONAL) Name of the subaccount.
091                 *
092                 * @param name The updated subaccount name, or {@code null} if not set (the default).
093                 *
094                 * @return This builder.
095                 */
096                public Builder name(String name) {
097                        this.name = name;
098                        return this;
099                }
100
101                /**
102                 * (OPTIONAL) Whether to use the primary account's balance.
103                 *
104                 * @param usePrimaryAccountBalance {@code true} if the balance is shared with the primary account or {@code null} if not set (the default).
105                 *
106                 * @return This builder.
107                 */
108                public Builder usePrimaryAccountBalance(boolean usePrimaryAccountBalance) {
109                        this.usePrimaryAccountBalance = usePrimaryAccountBalance;
110                        return this;
111                }
112
113                /**
114                 * (OPTIONAL) Whether to suspend this subaccount.
115                 *
116                 * @param suspended Whether this subaccount should be suspended, or {@code null} if not set (the default).
117                 *
118                 * @return This builder.
119                 */
120                public Builder suspended(boolean suspended) {
121                        this.suspended = suspended;
122                        return this;
123                }
124
125                /**
126                 * Builds the {@linkplain UpdateSubaccountRequest}.
127                 *
128                 * @return An instance of UpdateSubaccountRequest, populated with all fields from this builder.
129                 */
130                public UpdateSubaccountRequest build() {
131                        return new UpdateSubaccountRequest(this);
132                }
133        }
134}