package cz.moneta.test.dsl.util.task.auto.smartauto.vehicle;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.auto.smartauto.VehiclePage;
import cz.moneta.test.dsl.auto.smartauto.shared.*;
import cz.moneta.test.dsl.util.task.auto.smartauto.SmartAutoTasks;

import java.util.function.Function;

public class SearchTasks {

    private final Harness harness;
    private SmartAutoTasks smartAutoTasks;

    public SearchTasks(Harness harness) {
        this.harness = harness;
        this.smartAutoTasks = harness.tasks().auto().smartAuto();
    }

    public Function<VehiclePage, VehiclePage> searchVehicleWithFilters(FilterFuel filterFuel, String filterPower, FilterBodywork filterBodywork, FilterGearbox filterGearbox, FilterDoors filterDoors, Model model) {
        return start -> start.clickVehicleWithoutVin()
                .then(smartAutoTasks.data().fillFilters(filterFuel, filterPower, filterBodywork, filterGearbox, filterDoors))
                .clickSearchWithFilters()
                .clickSearchedVehicle(model);
    }

    public Function<VehiclePage, VehiclePage> searchVehicleWithInvalidVinFilters(String vin, FilterFuel filterFuel, String filterPower, FilterBodywork filterBodywork, FilterGearbox filterGearbox, FilterDoors filterDoors, Model model) {
        return start -> start.typeVehicleVin(vin)
                .clickSearchWithVin()
                .then(smartAutoTasks.data().fillFilters(filterFuel, filterPower, filterBodywork, filterGearbox, filterDoors))
                .clickSearchWithVin()
                .clickSearchedVehicle(model);
    }

    public Function<VehiclePage, VehiclePage> searchVehicleWithValidInvalidVinFilters(String vin, FilterFuel filterFuel, Model model) {
        return start -> start.typeVehicleVin(vin)
                .then(smartAutoTasks.data().fillFilterFuel1(filterFuel))
                .clickSearchWithFilters()
                .clickSearchedVehicle(model);
    }

    public Function<VehiclePage, VehiclePage> searchVehicleWithVin(String vin, FilterFuel fuel, Model model) {
        return start -> start.typeVehicleVin(vin)
                .then(smartAutoTasks.data().fillFilterFuel1(fuel))
                .clickSearchWithVin()
                .clickSearchedVehicle(model);
    }
}
