/*
 * 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.dashboard;

import com.arrebol.taxiservicios.model.admin.Sale;
import com.arrebol.taxiservicios.model.admin.Taxi;
import com.arrebol.taxiservicios.model.catalog.Location;
import com.arrebol.taxiservicios.model.core.Person;
import com.arrebol.taxiservicios.model.dashboard.ToCollect;
import com.arrebol.taxiservicios.model.view.dashboard.DashboardToCollectView;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.junit.Before;
import static org.junit.Assert.*;
import org.junit.Test;

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

    private DashboardController controller;

    public DashboardControllerTest() {
    }

    @Before
    public void setUp() {
        controller = new DashboardController();
    }

    //@Test
    public void getAllTaxiWithInsuranceEndDateToFinish() {
        try {
            List<Taxi> taxis = controller.getAllTaxiWithInsuranceEndDateToFinish();
            assertFalse(taxis.isEmpty());
        } catch (Exception e) {
            assertTrue(false);
        }
    }

    //@Test
    public void getAllDriverLicenseEndDateToFinish(Location location) {
        try {
            List<Person> drivers = controller.getAllDriverLicenseEndDateToFinish(location);
            assertFalse(drivers.isEmpty());
        } catch (Exception e) {
            assertTrue(false);
        }
    }

    //@Test
    public void getAllBirthDayPerson() {
        try {
            List<Person> person = controller.getAllBirthDayPerson();
            assertFalse(person.isEmpty());
        } catch (Exception e) {
            assertTrue(false);
        }
    }

    //@Test
    public void getSaleMetrics() {
        try {
            Object o = controller.getSaleMetrics();

            if (o instanceof Object[]) {
                Object[] t = (Object[]) o;
                for (Object object : t) {
                    System.out.println(object);
                }
            }

            assertNotNull(o);
        } catch (Exception e) {
            assertTrue(false);
        }
    }

    //@Test
    public void getTotalDrivers() {
        try {
            Object o = controller.getTotalDrivers();

            System.out.println(o.toString());

            assertNotNull(o);
        } catch (Exception e) {
            assertTrue(false);
        }
    }

    //@Test
    public void getAllSalesByDriver() {
        try {
            List<Sale> sales = controller.getAllSalesByDriver();

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

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

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

    //@Test
    public void getCollectByRange() {
        try {
            List<ToCollect> restDays = controller.getCollectByRange();

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

    //@Test
    public void countCollectByRange() {
        try {
            List<Object> collects = controller.countCollectByRange();

            for (Object collect : collects) {
                for (Object object : (Object[]) collect) {
                    System.out.println(object);
                }
            }

            assertNotNull(collects);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

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

            Calendar startDate = Calendar.getInstance();

            startDate.setTime(new Date());
            startDate.set(Calendar.YEAR, 2020);
            startDate.set(Calendar.MONTH, 2);// marzo
            startDate.set(Calendar.DAY_OF_MONTH, 29);

            Calendar endDate = Calendar.getInstance();

            endDate.setTime(new Date());
            endDate.set(Calendar.YEAR, 2020);
            endDate.set(Calendar.MONTH, 4);//Mayo
            endDate.set(Calendar.DAY_OF_MONTH, 10);

            List<Person> personLst = controller.findAllInADate(1, startDate.getTime(), endDate.getTime());

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

            assertFalse(personLst.isEmpty());
        } catch (Exception e) {
            assertFalse(true);
        }
    }

    //@Test
    public void findAllDashboardToCollectView() {
        try {
            List<DashboardToCollectView> result = controller.findAllDashboardToCollectView();
            assertFalse(result.isEmpty());
        } catch (Exception e) {
            assertTrue(false);
        }
    }

    @Test
    public void findPersonInBlackListByName() {
        try {
             assertFalse(controller.findPersonInBlackListByName("GusT").isEmpty());
        } catch (Exception e) {
            assertTrue(false);
        }
    }
}
