package org.jivesoftware.smack.filter;

import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.Objects;

public class PresenceTypeFilter extends FlexibleStanzaTypeFilter<Presence> {
   public static final PresenceTypeFilter AVAILABLE;
   public static final PresenceTypeFilter UNAVAILABLE;
   public static final PresenceTypeFilter SUBSCRIBE;
   public static final PresenceTypeFilter SUBSCRIBED;
   public static final PresenceTypeFilter UNSUBSCRIBE;
   public static final PresenceTypeFilter UNSUBSCRIBED;
   public static final PresenceTypeFilter ERROR;
   public static final PresenceTypeFilter PROBE;
   private final Presence.Type type;

   private PresenceTypeFilter(Presence.Type type) {
      super(Presence.class);
      this.type = (Presence.Type)Objects.requireNonNull(type, "type must not be null");
   }

   protected boolean acceptSpecific(Presence presence) {
      return presence.getType() == this.type;
   }

   public String toString() {
      return this.getClass().getSimpleName() + ": type=" + this.type;
   }

   static {
      AVAILABLE = new PresenceTypeFilter(Presence.Type.available);
      UNAVAILABLE = new PresenceTypeFilter(Presence.Type.unavailable);
      SUBSCRIBE = new PresenceTypeFilter(Presence.Type.subscribe);
      SUBSCRIBED = new PresenceTypeFilter(Presence.Type.subscribed);
      UNSUBSCRIBE = new PresenceTypeFilter(Presence.Type.unsubscribe);
      UNSUBSCRIBED = new PresenceTypeFilter(Presence.Type.unsubscribed);
      ERROR = new PresenceTypeFilter(Presence.Type.error);
      PROBE = new PresenceTypeFilter(Presence.Type.probe);
   }
}
