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 DomainAndResourcepartJid extends AbstractJid implements DomainFullJid {
   private final DomainBareJid domainBareJid;
   private final Resourcepart resource;
   private String cache;

   DomainAndResourcepartJid(String domain, String resource) throws XmppStringprepException {
      this.domainBareJid = new DomainpartJid(domain);
      this.resource = Resourcepart.from(resource);
   }

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

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

   public final boolean hasNoResource() {
      return false;
   }

   public BareJid asBareJidIfPossible() {
      return null;
   }

   public FullJid asFullJidIfPossible() {
      return null;
   }

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

   public DomainFullJid asDomainFullJidIfPossible() {
      return this;
   }

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

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

   public boolean isParentOf(FullJid fullJid) {
      return false;
   }

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

   public boolean isParentOf(DomainFullJid domainFullJid) {
      return this.domainBareJid.equals(domainFullJid.getDomain()) && this.resource.equals(domainFullJid.getResourcepart());
   }

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

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

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

   public String asUnescapedString() {
      return this.toString();
   }

   public Localpart maybeGetLocalpart() {
      return null;
   }

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

   public JidWithLocalpart asJidWithLocalpartIfPossible() {
      return null;
   }

   public JidWithResource asJidWithResourcepartIfPossible() {
      return this;
   }
}
