package org.jxmpp.jid.impl;

import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.DomainFullJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.JidWithLocalpart;
import org.jxmpp.jid.JidWithResource;
import org.jxmpp.jid.parts.Domainpart;
import org.jxmpp.jid.parts.Localpart;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;

public class LocalDomainAndResourcepartJid extends AbstractJid implements FullJid {
   private final BareJid bareJid;
   private final Resourcepart resource;
   private String cache;
   private String unescapedCache;

   LocalDomainAndResourcepartJid(String localpart, String domain, String resource) throws XmppStringprepException {
      this(new LocalAndDomainpartJid(localpart, domain), Resourcepart.from(resource));
   }

   LocalDomainAndResourcepartJid(BareJid bareJid, Resourcepart resource) {
      this.bareJid = bareJid;
      this.resource = resource;
   }

   public final Resourcepart getResource() {
      return this.resource;
   }

   public String toString() {
      if (this.cache != null) {
         return this.cache;
      } else {
         this.cache = this.bareJid.toString() + '/' + this.resource;
         return this.cache;
      }
   }

   public String asUnescapedString() {
      if (this.unescapedCache != null) {
         return this.unescapedCache;
      } else {
         this.unescapedCache = this.bareJid.asUnescapedString() + '/' + this.resource;
         return this.unescapedCache;
      }
   }

   public BareJid asBareJid() {
      return this.bareJid;
   }

   public String asBareJidString() {
      return this.asBareJid().toString();
   }

   public final boolean hasNoResource() {
      return false;
   }

   public BareJid asBareJidIfPossible() {
      return this.asBareJid();
   }

   public FullJid asFullJidIfPossible() {
      return this;
   }

   public DomainBareJid asDomainBareJidIfPossible() {
      return null;
   }

   public DomainFullJid asDomainFullJidIfPossible() {
      return null;
   }

   public Localpart getLocalpartOrNull() {
      return this.bareJid.getLocalpart();
   }

   public Resourcepart getResourceOrNull() {
      return this.getResource();
   }

   public boolean isParentOf(BareJid bareJid) {
      return false;
   }

   public boolean isParentOf(FullJid fullJid) {
      return this.equals(fullJid);
   }

   public boolean isParentOf(DomainBareJid domainBareJid) {
      return false;
   }

   public boolean isParentOf(DomainFullJid domainFullJid) {
      return false;
   }

   public DomainBareJid asDomainBareJid() {
      return this.bareJid.asDomainBareJid();
   }

   public Resourcepart getResourcepart() {
      return this.resource;
   }

   public Jid withoutResource() {
      return this.asBareJid();
   }

   public Domainpart getDomain() {
      return this.bareJid.getDomain();
   }

   public Localpart maybeGetLocalpart() {
      return this.bareJid.getLocalpart();
   }

   public Resourcepart maybeGetResourcepart() {
      return this.getResource();
   }

   public Localpart getLocalpart() {
      return this.bareJid.getLocalpart();
   }

   public JidWithLocalpart asJidWithLocalpartIfPossible() {
      return this;
   }

   public JidWithResource asJidWithResourcepartIfPossible() {
      return this;
   }
}
