/*
 * Copyright 2008-2026 Async-IO.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.atmosphere.room;

import org.atmosphere.cpr.AtmosphereResource;

/**
 * Event fired when a member joins or leaves a {@link Room}.
 *
 * @param type       the event type (JOIN or LEAVE)
 * @param room       the room where the event occurred
 * @param member     the resource that joined or left (null for virtual members)
 * @param memberInfo the application-level member identity, or null if not provided
 * @since 4.0
 */
public record PresenceEvent(Type type, Room room, AtmosphereResource member, RoomMember memberInfo) {

    /**
     * Convenience constructor without member info.
     */
    public PresenceEvent(Type type, Room room, AtmosphereResource member) {
        this(type, room, member, null);
    }

    /**
     * Constructor for virtual member events (no AtmosphereResource).
     */
    public PresenceEvent(Type type, Room room, RoomMember memberInfo) {
        this(type, room, null, memberInfo);
    }

    /**
     * @return true if this event is for a virtual (non-connection) member
     */
    public boolean isVirtual() {
        return member == null && memberInfo != null;
    }

    public enum Type {
        JOIN,
        LEAVE
    }
}
