package io.github.jklingsporn.vertx.jooq.shared.internal;

import io.github.jklingsporn.vertx.jooq.shared.UnexpectedJsonValueTypeException;

import java.util.function.Function;

/**
 * Created by jensklingsporn on 12.02.18.
 */
public interface VertxPojo {

    /**
     * Uses the given <code>json</code> to set this POJOs values.
     * @param json
     * @return a reference to this <code>VertxPOJO</code>
     */
    public VertxPojo fromJson(io.vertx.core.json.JsonObject json);

    /**
     * Converts this <code>VertxPOJO</code> into a <code>JsonObject</code>.
     * @return a JSON-representation of this POJO.
     */
    public io.vertx.core.json.JsonObject toJson();

    /**
     * For internal purposes only.<br>
     * Function to safely set a value inside a POJO. Helps users to find bugs if they accidentally put a value into
     * a <{@code JsonObject} with a wrong type.
     * @param setter the setter of this POJO
     * @param getter the getter to obtain the value from the <{@code JsonObject}
     * @param fieldName the name of the field
     * @param expectedFieldType the type of the field
     * @param <T> the value type
     * @param <U> the return type of the setter
     * @see <a href="https://github.com/jklingsporn/vertx-jooq/pull/110">Related PR</a>
     */
    public static <T,U> void setOrThrow(Function<T,U> setter, Function<String,T> getter, String fieldName, String expectedFieldType){
        try {
            setter.apply(getter.apply(fieldName));
        } catch (java.lang.ClassCastException e) {
            throw new UnexpectedJsonValueTypeException(fieldName,expectedFieldType,e);
        }
    }
}

@@ -898,17 +898,21 @@
  @param 
-s
+pojoS
 etter th
@@ -932,16 +932,27 @@
 his POJO
+'s property
 %0A     * 
@@ -958,17 +958,21 @@
  @param 
-g
+jsonG
 etter th
@@ -973,22 +973,24 @@
 ter the 
-getter
+function
  to obta
@@ -1063,37 +1063,52 @@
 the name of the 
-field
+POJO / JSON-property
 %0A     * @param e
@@ -1140,16 +1140,25 @@
  of the 
+property/
 field%0A  
@@ -1200,47 +1200,87 @@
  * @
-param %3CU%3E the return type of the setter
+see %3Ca href=%22https://github.com/jklingsporn/vertx-jooq/pull/110%22%3ERelated PR%3C/a%3E
 %0A   
@@ -1331,39 +1331,41 @@
 porn/vertx-jooq/
-pull/11
+issues/17
 0%22%3ERelated PR%3C/a
@@ -1351,34 +1351,37 @@
 es/170%22%3ERelated 
-PR
+Issue
 %3C/a%3E%0A     */%0A   
@@ -1397,18 +1397,16 @@
 tatic %3CT
-,U
 %3E void s
@@ -1430,12 +1430,16 @@
 n%3CT,
-U%3E s
+?%3E pojoS
 ette
@@ -1460,17 +1460,21 @@
 ring,T%3E 
-g
+jsonG
 etter, S
@@ -1543,17 +1543,21 @@
         
-s
+pojoS
 etter.ap
@@ -1560,17 +1560,21 @@
 r.apply(
-g
+jsonG
 etter.ap

remove setter return type from the API