package de.braintags.vertx.util.security;

import io.vertx.core.json.JsonObject;

public class JWTOptions {

  private static final IllegalArgumentException INCOMPATIBLE_CONFIG = new IllegalArgumentException(
      "Can only set expiresIn to seconds or minutes");

  private JsonObject header;
  private String algorithm = "HS256";
  private boolean noTimestamp = false;
  private long expiresInMinutes;
  private long expiresInSeconds;
  private JsonObject audience;
  private JsonObject issuer;
  private JsonObject subject;

  public JsonObject getHeader() {
    return header;
  }

  public JWTOptions setHeader(JsonObject header) {
    this.header = header;
    return this;
  }

  public String getAlgorithm() {
    return algorithm;
  }

  public JWTOptions setAlgorithm(String algorithm) {
    this.algorithm = algorithm;
    return this;
  }

  public boolean isNoTimestamp() {
    return noTimestamp;
  }

  public JWTOptions setNoTimestamp(boolean noTimestamp) {
    this.noTimestamp = noTimestamp;
    return this;
  }

  public long getExpiresInMinutes() {
    return expiresInMinutes;
  }

  public JWTOptions setExpiresInMinutes(long expiresInMinutes) {
    if (expiresInSeconds != 0) {
      throw INCOMPATIBLE_CONFIG;
    }
    this.expiresInMinutes = expiresInMinutes;
    return this;
  }

  public long getExpiresInSeconds() {
    return expiresInSeconds;
  }

  public JWTOptions setExpiresInSeconds(long expiresInSeconds) {
    if (expiresInMinutes != 0) {
      throw INCOMPATIBLE_CONFIG;
    }
    this.expiresInSeconds = expiresInSeconds;
    return this;
  }

  public JsonObject getAudience() {
    return audience;
  }

  public JWTOptions setAudience(JsonObject audience) {
    this.audience = audience;
    return this;
  }

  public JsonObject getIssuer() {
    return issuer;
  }

  public JWTOptions setIssuer(JsonObject issuer) {
    this.issuer = issuer;
    return this;
  }

  public JsonObject getSubject() {
    return subject;
  }

  public JWTOptions setSubject(JsonObject subject) {
    this.subject = subject;
    return this;
  }

  public JsonObject asJsonObject() {
    JsonObject json = new JsonObject();
    json.put("algorithm", algorithm);
    json.put("noTimestamp", noTimestamp);
    if (header != null) {
      json.put("header", header);
    }
    if (audience != null) {
      json.put("audience", audience);
    }
    if (issuer != null) {
      json.put("issuer", issuer);
    }
    if (subject != null) {
      json.put("subject", subject);
    }
    if (expiresInMinutes != 0) {
      json.put("expiresInMinutes", expiresInMinutes);
    }
    if (expiresInSeconds != 0) {
      json.put("expiresInSeconds", expiresInSeconds);
    }

    return json;
  }
}

@@ -36,16 +36,40 @@
 urity;%0A%0A
+import java.util.List;%0A%0A
 import i
@@ -390,36 +390,35 @@
 alse;%0A  private 
-long
+int
  expiresInMinute
@@ -430,20 +430,19 @@
 private 
-long
+int
  expires
@@ -462,26 +462,28 @@
 private 
-JsonObject
+List%3CString%3E
  audienc
@@ -495,26 +495,22 @@
 private 
-JsonObject
+String
  issuer;
@@ -520,26 +520,22 @@
 private 
-JsonObject
+String
  subject
@@ -625,16 +625,22 @@
 tHeader(
+final 
 JsonObje
@@ -793,16 +793,22 @@
 gorithm(
+final 
 String a
@@ -972,16 +972,22 @@
 mestamp(
+final 
 boolean 
@@ -1171,20 +1171,25 @@
 Minutes(
-long
+final int
  expires
@@ -1453,20 +1453,25 @@
 Seconds(
-long
+final int
  expires
@@ -1628,34 +1628,36 @@
 %7D%0A%0A  public 
-JsonObject
+List%3CString%3E
  getAudience
@@ -1719,26 +1719,34 @@
 udience(
-JsonObject
+final List%3CString%3E
  audienc
@@ -1807,34 +1807,30 @@
 %7D%0A%0A  public 
-JsonObject
+String
  getIssuer()
@@ -1886,26 +1886,28 @@
 tIssuer(
-JsonObject
+final String
  issuer)
@@ -1962,34 +1962,30 @@
 %7D%0A%0A  public 
-JsonObject
+String
  getSubject(
@@ -2044,26 +2044,28 @@
 Subject(
-JsonObject
+final String
  subject
@@ -2131,99 +2131,157 @@
 lic 
-JsonObject asJsonObject() %7B%0A    JsonObject js
+io.vertx.ext.jwt.JWTOptions asNativeOptions() %7B%0A    io.vertx.ext.jwt.JWTOptions opti
 on
+s
  = new 
-JsonObject();%0A    json.put(%22a
+io.vertx.ext.jwt.JWTOptions();%0A    options.setA
 lgorithm
 %22, a
@@ -2276,19 +2276,17 @@
 lgorithm
-%22, 
+(
 algorith
@@ -2297,19 +2297,20 @@
     
-json.put(%22n
+options.setN
 oTim
@@ -2315,19 +2315,17 @@
 imestamp
-%22, 
+(
 noTimest
@@ -2366,27 +2366,26 @@
     
-json.put(%22h
+options.setH
 eader
-%22, 
+(
 head
@@ -2433,29 +2433,28 @@
     
-json.put(%22a
+options.setA
 udience
-%22, 
+(
 audi
@@ -2502,27 +2502,26 @@
     
-json.put(%22i
+options.setI
 ssuer
-%22, 
+(
 issu
@@ -2568,28 +2568,27 @@
     
-json.put(%22s
+options.setS
 ubject
-%22, 
+(
 subj
@@ -2634,35 +2634,36 @@
  0) %7B%0A      
-json.put(%22e
+options.setE
 xpiresInMinu
@@ -2665,19 +2665,17 @@
 nMinutes
-%22, 
+(
 expiresI
@@ -2734,19 +2734,20 @@
     
-json.put(%22e
+options.setE
 xpir
@@ -2761,11 +2761,9 @@
 onds
-%22, 
+(
 expi
@@ -2795,20 +2795,23 @@
  return 
-js
+opti
 on
+s
 ;%0A  %7D%0A%7D%0A

migrate to vertx 3.5.1