001package org.intellimate.izou.sdk.frameworks.presence.events;
002
003import org.intellimate.izou.identification.Identification;
004import org.intellimate.izou.sdk.events.CommonEvents;
005import org.intellimate.izou.sdk.events.Event;
006
007import java.util.List;
008import java.util.Optional;
009
010/**
011 * this event guarantees that the user is not around anymore (as much as possible).
012 * @author LeanderK
013 * @version 1.0
014 */
015public class LeavingEvent extends Event {
016    /**
017     * this event does not mean the user is able to notice anything (can be used for warm-up), it indicates
018     * he might be
019     */
020    public static final String GENERAL_DESCRIPTOR = "izou.presence.general.leaving";
021    /**
022     * it means that the addon can guarantee that the user left an area near izou
023     */
024    public static final String STRICT_DESCRIPTOR = "izou.presence.strict.leaving";
025    /**
026     * it means that the addon can guarantee that the user entered an area near izou
027     */
028    public static final String ID = "izou.leaving";
029
030    /**
031     * Creates a new Event Object
032     *
033     * @param source      the source of the Event, most likely a this reference.
034     * @param descriptors the descriptors to initialize the Event with
035     * @throws IllegalArgumentException if one of the Arguments is null or empty
036     */
037    protected LeavingEvent(Identification source, List<String> descriptors) throws IllegalArgumentException {
038        super(CommonEvents.Type.RESPONSE_TYPE, source, descriptors);
039    }
040
041    /**
042     * creates a new LeavingEvent
043     * @param source the caller
044     * @param strict whether the addon can guarantee that the user is around
045     * @param descriptors the descriptors
046     * @return the optional PresenceEvent
047     */
048    public static Optional<LeavingEvent> createLeavingEvent(Identification source, boolean strict, List<String> descriptors) {
049        try {
050            if (strict) {
051                descriptors.add(STRICT_DESCRIPTOR);
052            } else {
053                descriptors.add(GENERAL_DESCRIPTOR);
054            }
055            descriptors.add(ID);
056            descriptors.add(CommonEvents.Descriptors.NOT_INTERRUPT);
057            LeavingEvent stopRequest = new LeavingEvent(source, descriptors);
058            return Optional.of(stopRequest);
059        } catch (IllegalArgumentException e) {
060            return Optional.empty();
061        }
062    }
063}