|
| 1 | +/* |
| 2 | + * Copyright 2025 Vonage |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.vonage.client.conversations; |
| 17 | + |
| 18 | +import com.fasterxml.jackson.annotation.JsonIgnore; |
| 19 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 20 | +import com.vonage.client.JsonableBaseObject; |
| 21 | + |
| 22 | +/** |
| 23 | + * Base class for events with the {@code channel} field. |
| 24 | + * |
| 25 | + * @since 8.19.0 |
| 26 | + */ |
| 27 | +abstract class AbstractChannelEvent<B extends AbstractChannelEvent.Body> extends EventWithBody<B> { |
| 28 | + AbstractChannelEvent() {} |
| 29 | + |
| 30 | + @SuppressWarnings("unchecked") |
| 31 | + AbstractChannelEvent(Builder<?, ?, ?> builder) { |
| 32 | + super((Event.Builder<? extends EventWithBody<? extends B>, ?>) builder); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * The main body container for events with a {@linkplain MemberChannel}. |
| 37 | + */ |
| 38 | + static class Body extends JsonableBaseObject { |
| 39 | + @JsonProperty("channel") MemberChannel channel; |
| 40 | + |
| 41 | + Body() {} |
| 42 | + |
| 43 | + Body(Builder<?, ?, ?> builder) { |
| 44 | + channel = builder.channel; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * The {@code channel} field. |
| 50 | + * |
| 51 | + * @return The channel object, or {@code null} if absent. |
| 52 | + */ |
| 53 | + @JsonIgnore |
| 54 | + public MemberChannel getChannel() { |
| 55 | + return body != null ? body.channel : null; |
| 56 | + } |
| 57 | + |
| 58 | + @SuppressWarnings("unchecked") |
| 59 | + static abstract class Builder<E extends AbstractChannelEvent<? extends T>, T extends AbstractChannelEvent.Body, B extends Builder<? extends E, ? extends T, ? extends B>> extends EventWithBody.Builder<E, B> { |
| 60 | + private MemberChannel channel; |
| 61 | + |
| 62 | + Builder(EventType type) { |
| 63 | + super(type); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Sets the channel for the event. |
| 68 | + * |
| 69 | + * @param channel The channel for the event. |
| 70 | + * |
| 71 | + * @return This builder. |
| 72 | + */ |
| 73 | + public B channel(MemberChannel channel) { |
| 74 | + this.channel = channel; |
| 75 | + return (B) this; |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments