// 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;
        Collection department = httpCjClient.readCollection(foundItem.getHref());

        Collection employees = httpCjClient.readCollection(department.getLink("employees").getHref());

        Iterator<Collection> employeeIter = new CollectionIterator(employees, httpCjClient);
        List<Item> employeeItems = new LinkedList<>();
        while(employeeIter.hasNext()) {
            employeeItems.addAll(employeeIter.next().getItems());
            System.out.println(employeeItems.size());
        }

        Collection finalEmployees = new Collection(employees.getHref(), employeeItems, employees.getQueries(), employees.getLinks(), employees.getTemplate());

        return finalEmployees.transform(new EmployeeTransformer());
    }

    public List<Department> getAllDepartments() {
        Collection departments = httpCjClient.readCollection(departmentsURI);

        Iterator<Collection> iterator = new CollectionIterator(departments, httpCjClient);
        List<Item> items = new LinkedList<>();
        while(iterator.hasNext()) {
            System.out.println("itearion!");
            items.addAll(iterator.next().getItems());
        }

        handlePossibleErrors(departments);

        Collection finalCollection = new Collection(departments.getHref(), items, departments.getQueries(), departments.getLinks(), departments.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;

        Collection department = httpCjClient.readCollection(foundItem.getHref());

        Collection employees = httpCjClient.readCollection(department.getLink("employees").getHref());

        Iterator<Collection> employeeIter = new CollectionIterator(employees, httpCjClient);
        List<Item> employeeItems = new LinkedList<>();
        while(employeeIter.hasNext()) {
            employeeItems.addAll(employeeIter.next().getItems());
            System.out.println(employeeItems.size());
        }

        Collection finalEmployees = new Collection(employees.getHref(), employeeItems, employees.getQueries(), employees.getLinks(), employees.getTemplate());

        return finalEmployees.transform(new EmployeeTransformer());
    }

    public List<Department> getAllDepartments() {
        Collection departments = httpCjClient.readCollection(departmentsURI);

        Iterator<Collection> iterator = new CollectionIterator(departments, httpCjClient);
        List<Item> items = new LinkedList<>();
        while(iterator.hasNext()) {
            System.out.println("itearion!");
            items.addAll(iterator.next().getItems());
        }

        handlePossibleErrors(departments);

        Collection finalCollection = new Collection(departments.getHref(), items, departments.getQueries(), departments.getLinks(), departments.getTemplate());

        return finalCollection.transform(new DepratmentTransformer());