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
020public class GenericEvent extends EventWithBody<Map<String, ?>> {
021
022    GenericEvent() {}
023
024    GenericEvent(Builder<?, ?> builder) {
025        super(builder);
026        body = builder.body;
027    }
028
029    /**
030     * Custom event data as key-value pairs.
031     *
032     * @return The event's main body as a Map.
033     */
034    public Map<String, ?> getBody() {
035        return body;
036    }
037
038    @SuppressWarnings("unchecked")
039    public static abstract class Builder<E extends GenericEvent,
040            B extends Builder<? extends E, ? extends  B>>
041            extends EventWithBody.Builder<GenericEvent, Builder<E, B>> {
042
043        private Map<String, ?> body;
044
045        Builder(EventType type) {
046            super(type);
047        }
048
049        /**
050         * Custom data send in the body.
051         *
052         * @param body The custom data as key-value pairs.
053         *
054         * @return This builder.
055         */
056        public B body(Map<String, ?> body) {
057            this.body = body;
058            return (B) this;
059        }
060    }
061}