/*
 * Arrebol Consultancy copyright.
 * 
 * This code belongs to Arrebol Consultancy
 * its use, redistribution or modification are prohibited 
 * without written authorization from Arrebol Consultancy.
 */
package com.arrebol.taxiservicios.controller.admin;

import com.arrebol.taxiservicios.model.admin.FeeByDriver;
import com.arrebol.taxiservicios.model.admin.Sanction;
import com.arrebol.taxiservicios.model.core.Person;
import com.arrebol.taxiservicios.model.core.User;
import com.arrebol.taxiservicios.model.enums.FeeType;
import com.arrebol.taxiservicios.model.enums.SanctionType;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.junit.Before;
import org.junit.Test;

/**
 *
 * @author Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
public class FeeByDriverControllerTest {

    private FeeByDriver feeByDriver;
    private FeeByDriverController controller;
    private Date startDate;
    private Date endDate;
    private String driverId;
    private Person driver_janitzio;
    private User user_ruben;

    @Before
    public void setUp() {
        Calendar start = Calendar.getInstance();
        Calendar end = Calendar.getInstance();

        //2019-03-07 09:07:04
        start.set(2021, 2, 13, 9, 7, 4);
        //2019-03-07 21:07:04
        end.set(2021, 6, 03, 21, 7, 4);

        startDate = start.getTime();
        endDate = end.getTime();
        user_ruben = new User("09ea84b8-b9d1-4a71-adfe-db653b2a9982", "");
        driver_janitzio = new Person("0063e1ac-3daf-4a03-a2de-ac7187c7853b");
        controller = new FeeByDriverController();

        feeByDriver = new FeeByDriver(
                UUID.randomUUID().toString(),
                driver_janitzio,
                new Date(),
                50D,
                user_ruben,
                new Date());

        feeByDriver.setStatus(FeeType.NO_PAID);
    }

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

            assertTrue(controller.saveFeeByDriver(feeByDriver));
        } catch (Exception e) {
            assertTrue(false);
        }
    }

    //@Test
    public void deleteFeeByDriverById() {
        try {
            assertTrue(controller.deleteFeeByDriverById("edaa2613-27b1-4e12-8a9c-b66a67192a5a"));
        } catch (Exception e) {
            assertTrue(false);
        }
    }

    //@Test
    public void findFeesBetweenDatesByDriver() {
        try {
            List<FeeByDriver> results = controller.findFeesBetweenDatesByDriver(startDate, endDate, driverId);

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

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

    //@Test
    public void updateFeeStatusById() {
        try {
            Sanction sanction = new Sanction(
                    UUID.randomUUID().toString(),
                    500D,
                    new Date(),
                    driver_janitzio,
                    "Pago de multa del chofer Janitzio Zavala Lopez por la cantidad de $500.00",
                    SanctionType.ADD,
                    user_ruben,
                    new Date());

            assertTrue(controller.updateFeeStatusById("26733d72-596e-4277-a53c-4a6e0f8f0618", FeeType.PAID, "TEST COMMENTS", new User("09ea84b8-b9d1-4a71-adfe-db653b2a9982", ""), sanction));
        } catch (Exception e) {
            assertTrue(false);
        }
    }

    //@Test
    public void payAllFeesByDriverId() {
        try {
            assertTrue(controller.payAllFeesByDriverId(driver_janitzio, user_ruben));
        } catch (Exception e) {
            assertTrue(false);
        }
    }

    //@Test
    public void findAllFeesByDriverAndStatus() {
        try {
            List<FeeByDriver> results = controller.findAllFeesByDriverAndStatus(driver_janitzio, FeeType.PAID);

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

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

    //@Test
    public void findAllFeesNoPaid() {
        try {
            List<FeeByDriver> results = controller.findAllFeesNoPaid();

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

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

    //@Test
    public void findTotalFeesByStatus() {
        try {
            List<FeeByDriver> results = controller.findTotalFeesByStatus(FeeType.NO_PAID);

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

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

    @Test
    public void updateAllFeesSelected() {
        try {
            Sanction sanction = new Sanction(
                    UUID.randomUUID().toString(),
                    200D,
                    new Date(),
                    driver_janitzio,
                    "Pago de multa del chofer Janitzio Zavala Lopez por la cantidad de $200.00",
                    SanctionType.ADD,
                    user_ruben,
                    new Date());
            
            List<String> ids = new ArrayList<>();

            ids.add("26733d72-596e-4277-a53c-4a6e0f8f0618");
            ids.add("35bbadac-647a-4111-9123-6b3a2793bd2c");
            ids.add("82bb909f-c651-4f46-a632-480a3e297263");
            ids.add("a3343b9b-c6cb-4a08-9c2d-e33124fc6754");

            assertTrue(controller.updateAllFeesSelected(ids, FeeType.PAID, user_ruben, "PAGADOS DESDE TEST CONTROLLER", sanction));
        } catch (Exception e) {
            assertTrue(false);
        }
    }
}
