package org.jivesoftware.smack.util.dns;

public class SRVRecord extends HostAddress implements Comparable<SRVRecord> {
   private int weight;
   private int priority;

   public SRVRecord(String fqdn, int port, int priority, int weight) {
      super(fqdn, port);
      if (weight >= 0 && weight <= 65535) {
         if (priority >= 0 && priority <= 65535) {
            this.priority = priority;
            this.weight = weight;
         } else {
            throw new IllegalArgumentException("DNS SRV records priority must be a 16-bit unsiged integer (i.e. between 0-65535. Priority was: " + priority);
         }
      } else {
         throw new IllegalArgumentException("DNS SRV records weight must be a 16-bit unsiged integer (i.e. between 0-65535. Weight was: " + weight);
      }
   }

   public int getPriority() {
      return this.priority;
   }

   public int getWeight() {
      return this.weight;
   }

   public int compareTo(SRVRecord other) {
      int res = other.priority - this.priority;
      if (res == 0) {
         res = this.weight - other.weight;
      }

      return res;
   }

   public String toString() {
      return super.toString() + " prio:" + this.priority + ":w:" + this.weight;
   }
}
