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.time.Instant;
019import java.util.Map;
020
021/**
022 * Represents filter options for {@link ConversationsClient#listUserConversations(String, ListUserConversationsRequest)}.
023 */
024public final class ListUserConversationsRequest extends AbstractListUserRequest {
025        private final MemberState state;
026        private final OrderBy orderBy;
027        private final Boolean includeCustomData;
028
029        ListUserConversationsRequest(Builder builder) {
030                super(builder);
031                state = builder.state;
032                orderBy = builder.orderBy;
033                includeCustomData = builder.includeCustomData;
034        }
035        
036        @Override
037        public Map<String, String> makeParams() {
038                Map<String, String> params = super.makeParams();
039                if (state != null) {
040            params.put("state", state.toString());
041        }
042                if (orderBy != null) {
043            params.put("order_by", orderBy.toString());
044        }
045                if (includeCustomData != null) {
046            params.put("include_custom_data", includeCustomData.toString());
047        }
048                return params;
049        }
050
051
052        @Override
053        public Instant getStartDate() {
054                return startDate;
055        }
056
057        /**
058         * Only include conversations with this member state.
059         *
060         * @return The state to filter by, or {@code null} if not specified.
061         */
062        public MemberState getState() {
063                return state;
064        }
065
066        /**
067         * Determines how the results should be compared and ordered.
068         *
069         * @return The result ordering strategy, or {@code null} if not specified.
070         */
071        public OrderBy getOrderBy() {
072                return orderBy;
073        }
074
075        /**
076         * Whether to include custom data in the responses.
077         *
078         * @return {@code true} if custom data should be included, or {@code null} if not specified.
079         */
080        public Boolean getIncludeCustomData() {
081                return includeCustomData;
082        }
083
084        /**
085         * Entry point for constructing an instance of this class.
086         * 
087         * @return A new Builder.
088         */
089        public static Builder builder() {
090                return new Builder();
091        }
092        
093        public static final class Builder extends AbstractConversationsFilterRequest.Builder<ListUserConversationsRequest, Builder> {
094                private MemberState state;
095                private OrderBy orderBy;
096                private Boolean includeCustomData;
097        
098                Builder() {}
099
100                @Override
101                public Builder startDate(Instant startDate) {
102                        return super.startDate(startDate);
103                }
104
105                /**
106                 * Only include conversations with this member state.
107                 *
108                 * @param state The state to filter by..
109                 *
110                 * @return This builder.
111                 */
112                public Builder state(MemberState state) {
113                        this.state = state;
114                        return this;
115                }
116
117                /**
118                 * Determines how the results should be compared and ordered.
119                 *
120                 * @param orderBy The result ordering strategy.
121                 *
122                 * @return This builder.
123                 */
124                public Builder orderBy(OrderBy orderBy) {
125                        this.orderBy = orderBy;
126                        return this;
127                }
128
129                /**
130                 * Whether to include custom data in the responses.
131                 *
132                 * @param includeCustomData {@code true} if custom data should be included.
133                 *
134                 * @return This builder.
135                 */
136                public Builder includeCustomData(Boolean includeCustomData) {
137                        this.includeCustomData = includeCustomData;
138                        return this;
139                }
140
141                /**
142                 * Builds the {@linkplain ListUserConversationsRequest}.
143                 *
144                 * @return An instance of ListUserConversationsRequest, populated with all fields from this builder.
145                 */
146                public ListUserConversationsRequest build() {
147                        return new ListUserConversationsRequest(this);
148                }
149        }
150}