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.JsonProperty; 019import com.vonage.client.Jsonable; 020import com.vonage.client.common.E164; 021 022public class NumberTransfer extends AbstractTransfer { 023 private String number, country; 024 025 protected NumberTransfer() { 026 } 027 028 NumberTransfer(Builder builder) { 029 super(builder); 030 number = new E164(builder.number).toString(); 031 if ((country = builder.country) == null || country.trim().length() != 2) { 032 throw new IllegalArgumentException("ISO 3166-1 alpha-2 country code is required."); 033 } 034 } 035 036 /** 037 * Country the number is registered in (ISO 3166-1 alpha-2 format). 038 * 039 * @return The two-letter country code for the number. 040 */ 041 @JsonProperty("country") 042 public String getCountry() { 043 return country; 044 } 045 046 /** 047 * The number being transferred between accounts. 048 * 049 * @return The transfer phone number in E164 format. 050 */ 051 @JsonProperty("number") 052 public String getNumber() { 053 return number; 054 } 055 056 /** 057 * Creates an instance of this class from a JSON payload. 058 * 059 * @param json The JSON string to parse. 060 * @return An instance of this class with the fields populated, if present. 061 */ 062 public static NumberTransfer fromJson(String json) { 063 return Jsonable.fromJson(json); 064 } 065 066 /** 067 * Entry point for constructing an instance of this class. 068 * 069 * @return A new Builder. 070 */ 071 public static Builder builder() { 072 return new Builder(); 073 } 074 075 public static class Builder extends AbstractTransfer.Builder<NumberTransfer, Builder> { 076 private String number, country; 077 078 Builder() {} 079 080 /** 081 * (REQUIRED) Country the number is registered in, in ISO 3166-1 alpha-2 format. 082 * 083 * @param country The two letter country code for the number. 084 * 085 * @return This builder. 086 */ 087 public Builder country(String country) { 088 this.country = country; 089 return this; 090 } 091 092 /** 093 * (REQUIRED) The number being transferred between accounts. 094 * 095 * @param number The transfer phone number in E164 format. 096 * 097 * @return This builder. 098 */ 099 public Builder number(String number) { 100 this.number = number; 101 return this; 102 } 103 104 105 /** 106 * Builds the {@linkplain NumberTransfer}. 107 * 108 * @return An instance of NumberTransfer, populated with all fields from this builder. 109 */ 110 public NumberTransfer build() { 111 return new NumberTransfer(this); 112 } 113 } 114}