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 com.fasterxml.jackson.annotation.JsonProperty;
019import com.vonage.client.JsonableBaseObject;
020import java.util.Map;
021
022/**
023 * Additional properties for a {@linkplain Conversation}.
024 */
025public class ConversationProperties extends JsonableBaseObject {
026        private Integer ttl;
027        private String type, customSortKey;
028        private Map<String, Object> customData;
029
030        ConversationProperties() {}
031
032        ConversationProperties(Builder builder) {
033                ttl = builder.ttl;
034                if ((type = builder.type) != null && (type.length() > 200 || type.trim().isEmpty())) {
035                        throw new IllegalArgumentException("Type must be between 1 and 200 characters.");
036                }
037                if ((customSortKey = builder.customSortKey) != null && (customSortKey.length() > 200 || customSortKey.trim().isEmpty())) {
038                        throw new IllegalArgumentException("Custom sort key must be between 1 and 200 characters.");
039                }
040                customData = builder.customData;
041        }
042
043        /**
044         * Number of seconds after which an empty conversation is deleted.
045         * 
046         * @return The empty time-to-live in seconds, or {@code null} if unspecified.
047         */
048        @JsonProperty("ttl")
049        public Integer getTtl() {
050                return ttl;
051        }
052
053        /**
054         * Conversation type.
055         * 
056         * @return The conversation type as a string, or {@code null} if unknown.
057         */
058        @JsonProperty("type")
059        public String getType() {
060                return type;
061        }
062
063        /**
064         * Custom sort key.
065         * 
066         * @return The custom sort key as a string, or {@code null} if unspecified.
067         */
068        @JsonProperty("custom_sort_key")
069        public String getCustomSortKey() {
070                return customSortKey;
071        }
072
073        /**
074         * Custom key-value pairs to be included with conversation data.
075         * 
076         * @return The custom properties as a Map, or {@code null} if unspecified.
077         */
078        @JsonProperty("custom_data")
079        public Map<String, Object> getCustomData() {
080                return customData;
081        }
082
083        /**
084         * Entry point for constructing an instance of this class.
085         * 
086         * @return A new Builder.
087         */
088        public static Builder builder() {
089                return new Builder();
090        }
091        
092        public static class Builder {
093                private Integer ttl;
094                private String type, customSortKey;
095                private Map<String, Object> customData;
096        
097                Builder() {}
098        
099                /**
100                 * Number of seconds after which an empty conversation is deleted.
101                 *
102                 * @param ttl The empty time-to-live in seconds, or {@code null} if unspecified.
103                 *
104                 * @return This builder.
105                 */
106                public Builder ttl(Integer ttl) {
107                        this.ttl = ttl;
108                        return this;
109                }
110
111                /**
112                 * Conversation type.
113                 *
114                 * @param type The conversation type as a string, or {@code null} if unknown.
115                 *
116                 * @return This builder.
117                 */
118                public Builder type(String type) {
119                        this.type = type;
120                        return this;
121                }
122
123                /**
124                 * Custom sort key.
125                 *
126                 * @param customSortKey The custom sort key as a string, or {@code null} if unspecified.
127                 *
128                 * @return This builder.
129                 */
130                public Builder customSortKey(String customSortKey) {
131                        this.customSortKey = customSortKey;
132                        return this;
133                }
134
135                /**
136                 * Custom key-value pairs to be included with conversation data.
137                 *
138                 * @param customData The custom properties as a Map, or {@code null} if unspecified.
139                 *
140                 * @return This builder.
141                 */
142                public Builder customData(Map<String, Object> customData) {
143                        this.customData = customData;
144                        return this;
145                }
146
147        
148                /**
149                 * Builds the {@linkplain ConversationProperties}.
150                 *
151                 * @return An instance of ConversationProperties, populated with all fields from this builder.
152                 */
153                public ConversationProperties build() {
154                        return new ConversationProperties(this);
155                }
156        }
157}