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.*;
019import com.vonage.client.JsonableBaseObject;
020
021public class MemberInitiator extends JsonableBaseObject {
022        @JsonProperty("invited") private Invited invited;
023        @JsonProperty("joined") private Joined joined;
024
025        protected MemberInitiator() {
026        }
027
028        private static class Invited extends JsonableBaseObject {
029                @JsonProperty("is_system") Boolean isSystem;
030        }
031
032        private static class Joined extends Invited {
033                @JsonProperty("user_id") String userId;
034                @JsonProperty("member_id") String memberId;
035        }
036
037        /**
038         * Whether the member was invited by an admin JWT or a user.
039         *
040         * @return {@code true} if invited by admin JWT,
041         * {@code false} if invited by user (joined), {@code null} if unknown.
042         */
043        @JsonIgnore
044        public Boolean invitedByAdmin() {
045                return invited != null ? invited.isSystem : joined != null ? joined.isSystem : null;
046        }
047
048        /**
049         * If {@linkplain #invitedByAdmin()} is {@code false}, returns the ID of the inviting user.
050         *
051         * @return The user ID that invited this member, or {@code null} if not applicable.
052         */
053        @JsonIgnore
054        public String getUserId() {
055                return joined != null ? joined.userId : null;
056        }
057
058        /**
059         * If {@linkplain #invitedByAdmin()} is {@code false}, returns the ID of the inviting member.
060         *
061         * @return The member ID that sent the invite, or {@code null} if not applicable.
062         */
063        @JsonIgnore
064        public String getMemberId() {
065                return joined != null ? joined.memberId : null;
066        }
067}