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.conversations; 017 018import java.util.Map; 019 020/** 021 * Filters results for {@link ConversationsClient#listEvents(String, ListEventsRequest)}. 022 */ 023public class ListEventsRequest extends AbstractConversationsFilterRequest { 024 private final Boolean excludeDeletedEvents; 025 private final Integer startId, endId; 026 private final EventType eventType; 027 028 ListEventsRequest(Builder builder) { 029 super(builder); 030 excludeDeletedEvents = builder.excludeDeletedEvents; 031 startId = builder.startId; 032 endId = builder.endId; 033 eventType = builder.eventType; 034 } 035 036 @Override 037 public Map<String, String> makeParams() { 038 Map<String, String> params = super.makeParams(); 039 if (excludeDeletedEvents != null) { 040 params.put("exclude_deleted_events", excludeDeletedEvents.toString()); 041 } 042 if (startId != null) { 043 params.put("start_id", String.valueOf(startId)); 044 } 045 if (endId != null) { 046 params.put("end_id", String.valueOf(endId)); 047 } 048 if (eventType != null) { 049 params.put("event_type", eventType.toString()); 050 } 051 return params; 052 } 053 054 /** 055 * Whether to exclude deleted events from the results. 056 * 057 * @return {@code true} to exclude deleted events, or {@code null} if unspecified. 058 */ 059 public Boolean getExcludeDeletedEvents() { 060 return excludeDeletedEvents; 061 } 062 063 /** 064 * The ID to start returning events at. 065 * 066 * @return The start ID as an Integer, or {@code null} if unspecified. 067 */ 068 public Integer getStartId() { 069 return startId; 070 } 071 072 /** 073 * The ID to stop returning events at. 074 * 075 * @return The end ID as an Integer, or {@code null} if unspecified. 076 */ 077 public Integer getEndId() { 078 return endId; 079 } 080 081 /** 082 * The type of event to search for. Does not currently support custom events. 083 * 084 * @return The event type to search for, or {@code null} if unspecified. 085 */ 086 public EventType getEventType() { 087 return eventType; 088 } 089 090 091 /** 092 * Entry point for constructing an instance of this class. 093 * 094 * @return A new Builder. 095 */ 096 public static Builder builder() { 097 return new Builder(); 098 } 099 100 public static final class Builder extends AbstractConversationsFilterRequest.Builder<ListEventsRequest, Builder> { 101 private Boolean excludeDeletedEvents; 102 private Integer startId, endId; 103 private EventType eventType; 104 105 Builder() {} 106 107 /** 108 * Whether to exclude deleted events from the results. 109 * 110 * @param excludeDeletedEvents {@code true} to exclude deleted events, or {@code null} if unspecified. 111 * 112 * @return This builder. 113 */ 114 public Builder excludeDeletedEvents(boolean excludeDeletedEvents) { 115 this.excludeDeletedEvents = excludeDeletedEvents; 116 return this; 117 } 118 119 /** 120 * The ID to start returning events at. 121 * 122 * @param startId The start ID as an int. 123 * 124 * @return This builder. 125 */ 126 public Builder startId(int startId) { 127 this.startId = startId; 128 return this; 129 } 130 131 /** 132 * The ID to stop returning events at. 133 * 134 * @param endId The end ID as an int. 135 * 136 * @return This builder. 137 */ 138 public Builder endId(int endId) { 139 this.endId = endId; 140 return this; 141 } 142 143 /** 144 * The type of event to search for. Does not currently support custom events. 145 * 146 * @param eventType The event type to search for as an enum. 147 * 148 * @return This builder. 149 */ 150 public Builder eventType(EventType eventType) { 151 this.eventType = eventType; 152 return this; 153 } 154 155 /** 156 * Builds the {@linkplain ListEventsRequest}. 157 * 158 * @return An instance of ListEventsRequest, populated with all fields from this builder. 159 */ 160 public ListEventsRequest build() { 161 return new ListEventsRequest(this); 162 } 163 } 164}