// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/DepratmentTransformer.java
// public class DepratmentTransformer implements ReadTransformation<Department> {
//     @Override
//     public Department transform(Item item) {
//         return new Department(item.getString("dept_no"), item.getString("dept_name"), item.getHref());
//     }
// }
// 
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/EmployeeTransformer.java
// public class EmployeeTransformer extends TwoWayTransformer<Employee> {
// 
//     @Override
//     public Employee transform(Item item) {
// 
//         return new Employee(item.getInt("emp_no"),
//                 item.getString("birth_date"),
//                 item.getString("first_name"),
//                 item.getString("last_name"),
//                 item.getString("gender"));
//     }
// 
//     @Override
//     public Item transform(Employee input) {
//         Item item = new Item();
//         item.addData(create("birth_date", input.getBirthday()));
//         item.addData(create("first_name", input.getFirstName()));
//         item.addData(create("last_name", input.getLastName()));
//         item.addData(create("gender", input.getGender()));
// 
//         return item;
//     }
// }


import de.fesere.hypermedia.cj.example.employeeDB.transformations.DepratmentTransformer;
import de.fesere.hypermedia.cj.example.employeeDB.transformations.EmployeeTransformer;
import de.fesere.hypermedia.cj.model.*;
import java.net.URI;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
package de.fesere.hypermedia.cj.example.employeeDB;



public class EmployeeDB {

    private final CjClient httpCjClient = new CjClient(new ApacheClient());

    private URI departmentsURI = null;
    private final URI employeesURI;


    public EmployeeDB() {
        URI START = URI.create("http://employee.herokuapp.com");
        Collection rootCollection = httpCjClient.readCollection(START);

        handlePossibleErrors(rootCollection);

        departmentsURI = rootCollection.getLink("departments").getHref();
        employeesURI = rootCollection.getLink("employees").getHref();
    }

    void handlePossibleErrors(Collection collection) {
        if(collection.hasError()) {
            throw new RuntimeException(collection.getError().getMessage());
        }
    }

    public void addNewEmployee(Employee employee) {
        Collection employees = httpCjClient.readCollection(employeesURI);

        Template template = employees.getTemplate();
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/DepratmentTransformer.java
// public class DepratmentTransformer implements ReadTransformation<Department> {
//     @Override
//     public Department transform(Item item) {
//         return new Department(item.getString("dept_no"), item.getString("dept_name"), item.getHref());
//     }
// }
// 
// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/transformations/EmployeeTransformer.java
// public class EmployeeTransformer extends TwoWayTransformer<Employee> {
// 
//     @Override
//     public Employee transform(Item item) {
// 
//         return new Employee(item.getInt("emp_no"),
//                 item.getString("birth_date"),
//                 item.getString("first_name"),
//                 item.getString("last_name"),
//                 item.getString("gender"));
//     }
// 
//     @Override
//     public Item transform(Employee input) {
//         Item item = new Item();
//         item.addData(create("birth_date", input.getBirthday()));
//         item.addData(create("first_name", input.getFirstName()));
//         item.addData(create("last_name", input.getLastName()));
//         item.addData(create("gender", input.getGender()));
// 
//         return item;
//     }
// }


// Path: src/test/java/de/fesere/hypermedia/cj/example/employeeDB/EmployeeDB.java
import de.fesere.hypermedia.cj.example.employeeDB.transformations.DepratmentTransformer;
import de.fesere.hypermedia.cj.example.employeeDB.transformations.EmployeeTransformer;
import de.fesere.hypermedia.cj.model.*;
import java.net.URI;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

package de.fesere.hypermedia.cj.example.employeeDB;



public class EmployeeDB {

    private final CjClient httpCjClient = new CjClient(new ApacheClient());

    private URI departmentsURI = null;
    private final URI employeesURI;


    public EmployeeDB() {
        URI START = URI.create("http://employee.herokuapp.com");
        Collection rootCollection = httpCjClient.readCollection(START);

        handlePossibleErrors(rootCollection);

        departmentsURI = rootCollection.getLink("departments").getHref();
        employeesURI = rootCollection.getLink("employees").getHref();
    }

    void handlePossibleErrors(Collection collection) {
        if(collection.hasError()) {
            throw new RuntimeException(collection.getError().getMessage());
        }
    }

    public void addNewEmployee(Employee employee) {
        Collection employees = httpCjClient.readCollection(employeesURI);

        Template template = employees.getTemplate();
        template.fill(new EmployeeTransformer().transform(employee));