/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arrebol.taxiservicios.controller.admin;

import com.arrebol.taxiservicios.model.admin.Reference;
import com.arrebol.taxiservicios.model.catalog.Location;
import com.arrebol.taxiservicios.model.core.Person;
import com.arrebol.taxiservicios.model.core.User;
import com.arrebol.taxiservicios.model.enums.PersonType;
import com.arrebol.taxiservicios.model.enums.ReferenceType;
import com.arrebol.taxiservicios.model.view.PersonListView;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Picasso
 */
public class DriverControllerUnitTest {

    private static final String DRIVER_ID = "0063e1ac-3daf-4a03-a2de-ac7187c7853b";
    private static final String USER_ID = "09ea84b8-b9d1-4a71-adfe-db653b2a9982";
    private static final String REFERENCE_UPDATE_ID = "a4d573be-f443-49c6-852e-9ac3f2ab6ae0";
    private static final String REFERENCE_UPDATE_ID_2 = "fb170f9b-abab-49c4-8799-9602d0374bf2";

    private DriverController controller;
    private List<Reference> references;

    public DriverControllerUnitTest() {
    }

    @Before
    public void setUp() {
        controller = new DriverController();
        references = new ArrayList<Reference>();
    }

    //@Test
    public void getAllPersonsByPersonTye() {
        try {
            List<Person> drivers = controller.getAllPersonsByPersonTye(PersonType.DRIVER);

            assertFalse(drivers.isEmpty());
        } catch (Exception e) {
            assertTrue(false);
        }
    }

    //@Test
    public void updateReference() {
        try {

            Reference reference = new Reference(REFERENCE_UPDATE_ID);
            boolean save = false;

            reference.setCompleteName("Maria Bonita Ramirez Nodal");
            reference.setPhone("3319918012");
            reference.setCompleteAddress("Tres lagos.");
            reference.setLastUpdatedBy(new User(USER_ID, ""));
            reference.setPerson(new Person(DRIVER_ID));
            reference.setReferenceType(ReferenceType.OTHER);

            references.add(reference);

            reference = new Reference(REFERENCE_UPDATE_ID_2);

            reference.setCompleteName("Janitzio Zavala López");
            reference.setPhone("3319917031");
            reference.setCompleteAddress("Eutimio Pinzon.");
            reference.setLastUpdatedBy(new User(USER_ID, ""));
            reference.setPerson(new Person(DRIVER_ID));
            reference.setReferenceType(ReferenceType.FRIEND);

            references.add(reference);

            assertTrue(controller.saveOrUpdateReference(references, save));
        } catch (Exception e) {
            assertNotNull(null);
        }
    }

    //@Test
    public void saveReference() {
        try {
            boolean save = true;
            for (int i = 0; i < 2; i++) {
                Reference reference = new Reference(UUID.randomUUID().toString());

                reference.setCreatedBy(new User(USER_ID, ""));

                if (0 == 1) {
                    reference.setCompleteName("Maria Bonita Ramirez Nodal");
                    reference.setPhone("3319918012");
                    reference.setCompleteAddress("Tres lagos.");
                    reference.setPerson(new Person(DRIVER_ID));
                    reference.setReferenceType(ReferenceType.OTHER);
                } else {
                    reference.setCompleteName("Janitzio Zavala López");
                    reference.setPhone("3319917031");
                    reference.setCompleteAddress("Eutimio Pinzon.");
                    reference.setPerson(new Person(DRIVER_ID));
                    reference.setReferenceType(ReferenceType.FRIEND);
                }
                references.add(reference);
            }

            assertTrue(controller.saveOrUpdateReference(references, save));
        } catch (Exception e) {
            assertNotNull(null);
        }
    }

    //@Test
    public void updateStatusDriverAndRemoveFromTaxi() {
        try {
            assertTrue(controller.updateStatusDriverAndRemoveFromTaxi(DRIVER_ID, new User(USER_ID, "")));
        } catch (Exception e) {
            assertNotNull(null);
        }
    }

    //@Test
    public void getAllPersonsPoolByPersonTye() {
        try {
            assertFalse(controller.getAllPersonsPoolByPersonTye(PersonType.DRIVER).isEmpty());
        } catch (Exception e) {
            assertNotNull(null);
        }
    }

    //@Test
    public void findListOfPersonsByType() {
        try {
            List<PersonListView> results = controller.findListOfPersonsByType(PersonType.CUSTOMER, new Location());

            results.forEach(System.out::println);

            assertFalse(results.isEmpty());
        } catch (Exception e) {
            assertNotNull(null);
        }
    }
}
