001package org.intellimate.izou.sdk.frameworks.presence.resources;
002
003import org.intellimate.izou.events.EventModel;
004import org.intellimate.izou.identification.Identification;
005import org.intellimate.izou.resource.ResourceModel;
006import org.intellimate.izou.sdk.resource.Resource;
007
008import java.util.Optional;
009
010/**
011 * this Resource holds an integer containing the Seconds passed since the User was last encountered
012 * @author LeanderK
013 * @version 1.0
014 */
015public class LastEncountered extends Resource<Long> {
016    public static final String ID = "izou.presence.resources.lastencountered";
017
018    /**
019     * creates a new Resource.
020     *
021     * @param provider   the Provider of the Resource
022     * @param timePassed the time passed in seconds
023     */
024    public LastEncountered(Identification provider, Long timePassed) {
025        super(ID, provider, timePassed);
026    }
027
028    /**
029     * returns the time passed if available
030     * @param eventModel the event
031     * @return the optional long
032     */
033    @SuppressWarnings("unused")
034    public static Optional<Long> getTimePassed(EventModel eventModel) {
035        if (eventModel.getListResourceContainer().containsResourcesFromSource(ID)) {
036            return eventModel
037                    .getListResourceContainer()
038                    .provideResource(ID)
039                    .stream()
040                    .map(ResourceModel::getResource)
041                    .filter(ob -> ob instanceof Long)
042                    .map(ob -> (Long) ob)
043                    .findAny();
044        } else {
045            return Optional.empty();
046        }
047    }
048}