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.users.channels; 017 018import com.fasterxml.jackson.annotation.JsonProperty; 019import com.vonage.client.JsonableBaseObject; 020import java.util.ArrayList; 021import java.util.Collection; 022import java.util.List; 023 024/** 025 * Represents the "channels" field on {@link com.vonage.client.users.User}. 026 */ 027public final class Channels extends JsonableBaseObject { 028 @JsonProperty("pstn") private List<Pstn> pstn; 029 @JsonProperty("sip") private List<Sip> sip; 030 @JsonProperty("vbc") private List<Vbc> vbc; 031 @JsonProperty("websocket") private List<Websocket> websocket; 032 @JsonProperty("sms") private List<Sms> sms; 033 @JsonProperty("mms") private List<Mms> mms; 034 @JsonProperty("whatsapp") private List<Whatsapp> whatsapp; 035 @JsonProperty("viber") private List<Viber> viber; 036 @JsonProperty("messenger") private List<Messenger> messenger; 037 038 Channels() { 039 } 040 041 private <C extends Channel> List<C> initChannelList(List<C> channelList) { 042 return channelList != null ? channelList : new ArrayList<>(2); 043 } 044 045 /** 046 * Creates a new Channels object and assigns the specified channels to the 047 * appropriate fields based on their type. 048 * 049 * @param channels The contact methods to associate with this user. 050 */ 051 public Channels(Collection<? extends Channel> channels) { 052 if (channels == null || channels.isEmpty()) return; 053 for (Channel channel : channels) { 054 if (channel instanceof Pstn) { 055 (pstn = initChannelList(pstn)).add((Pstn) channel); 056 } 057 else if (channel instanceof Sip) { 058 (sip = initChannelList(sip)).add((Sip) channel); 059 } 060 else if (channel instanceof Vbc) { 061 (vbc = initChannelList(vbc)).add((Vbc) channel); 062 } 063 else if (channel instanceof Websocket) { 064 (websocket = initChannelList(websocket)).add((Websocket) channel); 065 } 066 else if (channel instanceof Sms) { 067 (sms = initChannelList(sms)).add((Sms) channel); 068 } 069 else if (channel instanceof Mms) { 070 (mms = initChannelList(mms)).add((Mms) channel); 071 } 072 else if (channel instanceof Whatsapp) { 073 (whatsapp = initChannelList(whatsapp)).add((Whatsapp) channel); 074 } 075 else if (channel instanceof Viber) { 076 (viber = initChannelList(viber)).add((Viber) channel); 077 } 078 else if (channel instanceof Messenger) { 079 (messenger = initChannelList(messenger)).add((Messenger) channel); 080 } 081 } 082 } 083 084 /** 085 * PSTN channels. 086 * 087 * @return The list of PSTN channels, or {@code null} if not set. 088 */ 089 public List<Pstn> getPstn() { 090 return pstn; 091 } 092 093 /** 094 * SIP channels. 095 * 096 * @return The list of SIP channels, or {@code null} if not set. 097 */ 098 public List<Sip> getSip() { 099 return sip; 100 } 101 102 /** 103 * VBC channels. 104 * 105 * @return The list of VBC channels, or {@code null} if not set. 106 */ 107 public List<Vbc> getVbc() { 108 return vbc; 109 } 110 111 /** 112 * Websocket channels. 113 * 114 * @return The list of Websocket channels, or {@code null} if not set. 115 */ 116 public List<Websocket> getWebsocket() { 117 return websocket; 118 } 119 120 /** 121 * SMS channels. 122 * 123 * @return The list of SMS channels, or {@code null} if not set. 124 */ 125 public List<Sms> getSms() { 126 return sms; 127 } 128 129 /** 130 * MMS channels. 131 * 132 * @return The list of MMS channels, or {@code null} if not set. 133 */ 134 public List<Mms> getMms() { 135 return mms; 136 } 137 138 /** 139 * WhatsApp channels. 140 * 141 * @return The list of WhatsApp channels, or {@code null} if not set. 142 */ 143 public List<Whatsapp> getWhatsapp() { 144 return whatsapp; 145 } 146 147 /** 148 * Viber channels. 149 * 150 * @return The list of Viber channels, or {@code null} if not set. 151 */ 152 public List<Viber> getViber() { 153 return viber; 154 } 155 156 /** 157 * Messenger channels. 158 * 159 * @return The list of Messenger channels, or {@code null} if not set. 160 */ 161 public List<Messenger> getMessenger() { 162 return messenger; 163 } 164}