001 002/* 003 * Copyright 2024 Vonage 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package com.vonage.client.messages.whatsapp; 018 019import com.fasterxml.jackson.annotation.JsonProperty; 020import com.vonage.client.messages.MessageType; 021import java.util.LinkedHashMap; 022import java.util.Map; 023 024/** 025 * @since 7.2.0 026 */ 027public final class WhatsappLocationRequest extends WhatsappRequest { 028 final Map<String, Object> custom; 029 030 WhatsappLocationRequest(Builder builder) { 031 super(builder, MessageType.CUSTOM); 032 custom = new LinkedHashMap<>(4); 033 custom.put("type", "location"); 034 custom.put("location", new Location(builder)); 035 } 036 037 @JsonProperty("custom") 038 public Map<String, ?> getCustom() { 039 return custom; 040 } 041 042 public static Builder builder() { 043 return new Builder(); 044 } 045 046 public static final class Builder extends WhatsappRequest.Builder<WhatsappLocationRequest, Builder> { 047 String name, address; 048 Double latitude, longitude; 049 050 Builder() {} 051 052 /** 053 * (REQUIRED) 054 * Latitude of the location. 055 * 056 * @param latitude The latitude as a double. 057 * @return This builder. 058 */ 059 public Builder latitude(double latitude) { 060 this.latitude = latitude; 061 return this; 062 } 063 064 /** 065 * (REQUIRED) 066 * Longitude of the location. 067 * 068 * @param longitude The longitude as a double. 069 * @return This builder. 070 */ 071 public Builder longitude(double longitude) { 072 this.longitude = longitude; 073 return this; 074 } 075 076 /** 077 * (OPTIONAL) 078 * Name of the location. 079 * 080 * @param name The location name. 081 * @return This builder. 082 */ 083 public Builder name(String name) { 084 this.name = name; 085 return this; 086 } 087 088 /** 089 * (OPTIONAL) 090 * Address of the location. Only displayed if name is present. 091 * 092 * @param address The location address as a string. 093 * @return This builder. 094 */ 095 public Builder address(String address) { 096 this.address = address; 097 return this; 098 } 099 100 @Override 101 public WhatsappLocationRequest build() { 102 return new WhatsappLocationRequest(this); 103 } 104 } 105}