001package org.intellimate.izou.sdk.frameworks.permanentSoundOutput.events;
002
003import org.intellimate.izou.identification.Identification;
004import org.intellimate.izou.sdk.events.CommonEvents;
005import org.intellimate.izou.sdk.events.Event;
006import org.intellimate.izou.sdk.frameworks.common.resources.SelectorResource;
007import org.intellimate.izou.system.sound.SoundIDs;
008
009import java.util.ArrayList;
010import java.util.Arrays;
011import java.util.Optional;
012
013/**
014 * signals that every Sound-Output should mute
015 * @author LeanderK
016 * @version 1.0
017 */
018public class MuteEvent extends Event {
019    public static final String ID = SoundIDs.MuteEvent.descriptor;
020    /**
021     * Creates a new Event Object
022     *
023     * @param source      the source of the Event, most likely a this reference.
024     * @throws IllegalArgumentException if one of the Arguments is null or empty
025     */
026    protected MuteEvent(Identification source)
027            throws IllegalArgumentException {
028        super(CommonEvents.Type.RESPONSE_TYPE, source, new ArrayList<>(Arrays.asList(ID,
029                CommonEvents.Descriptors.NOT_INTERRUPT)));
030    }
031
032    /**
033     * creates a new MuteEvent
034     * @param source the caller
035     * @param target the target who should start playing
036     * @return the optional StartMusicRequest
037     */
038    public static Optional<MuteEvent> createMuteEvent(Identification source, Identification target) {
039        if (target == null || target.equals(source))
040            return Optional.empty();
041        try {
042            MuteEvent muteRequest = new MuteEvent(source);
043            muteRequest.addResource(new SelectorResource(source, target));
044            return Optional.of(muteRequest);
045        } catch (IllegalArgumentException e) {
046            return Optional.empty();
047        }
048    }
049
050    /**
051     * creates a new MuteEvent, will mute everything
052     * @param source the caller
053     * @return the optional StartMusicRequest
054     */
055    public static Optional<MuteEvent> createMuteEvent(Identification source) {
056        if (source == null)
057            return Optional.empty();
058        try {
059            MuteEvent muteRequest = new MuteEvent(source);
060            return Optional.of(muteRequest);
061        } catch (IllegalArgumentException e) {
062            return Optional.empty();
063        }
064    }
065}