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 DataTasks {

    private final Harness harness;
    private SmartAutoTasks smartAutoTasks;

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

    public Function<VehiclePage, VehiclePage> checkAndAddAdditionalData(FilterFuel filterFuel, int mileage, String description, ImportVehicle importVehicle, DealerIsOwner dealerIsOwner) {
        return start -> start.checkEngineCapacity()
                .checkEngineKw()
                .checkWeightTotal()
                .checkSeats()
                .checkFuel(filterFuel)
                .typeMileage(mileage)
                .typeDescription(description)
                .clickImportVehicle(importVehicle)
                .clickDealerIsOwner(dealerIsOwner);
    }

    public Function<VehiclePage, VehiclePage> fillAgroAdditionalDataWithoutTP(String note) {
        return start -> start
                .typeAgroNote(note);
    }

    public Function<VehiclePage, VehiclePage> fillFilters(FilterFuel filterFuel, String filterPower, FilterBodywork filterBodywork, FilterGearbox filterGearbox, FilterDoors filterDoors) {
        return start -> start.then(smartAutoTasks.data().fillFilterFuel1(filterFuel))
                .typeFilterPower(filterPower)
                .typeFilterBodywork(filterBodywork.getValue())
                .clickFilterBodywork(filterBodywork)
                .typeFilterGearbox(filterGearbox.getValue())
                .clickFilterGearbox(filterGearbox)
                .typeFilterDoors(filterDoors.getValue())
                .clickFilterDoors(filterDoors);
    }

    public Function<VehiclePage, VehiclePage> checkVehicleInformation(Brand brand, Model model) {
        return start -> start.checkVehicleInformationBrand(brand)
                .checkVehicleInformationModel(model);
    }

    public Function<VehiclePage, VehiclePage> checkAgroInformation(Brand brand, Model model) {
        return start -> start.checkAgroInformationBrand(brand)
                .checkAgroInformationModel(model);
    }

    public Function<VehiclePage, VehiclePage> fillFilterFuel1(FilterFuel fillFilterFuel) {
        return start -> start.typeFilterFuel(fillFilterFuel.getValue())
                .clickFilterFuel(fillFilterFuel);
    }

    public Function<VehiclePage, VehiclePage> fillFilterFuel2(FilterFuel filterFuel, int mileage, String description, ImportVehicle importVehicle, DealerIsOwner dealerIsOwner) {
        return start -> start.typeFilterFuel2(filterFuel.getValue())
                .clickFilterFuel2(filterFuel)
                .checkEngineCapacity()
                .checkWeightTotal()
                .checkSeats()
                .typeMileage(mileage)
                .typeDescription(description)
                .clickImportVehicle(importVehicle)
                .clickDealerIsOwner(dealerIsOwner);
    }

    public Function<VehiclePage, VehiclePage> fillDeferredDrawing(String description, String accessory) {
        return start -> start.typeAgroNote(description)
                .typeAgroAccessory(accessory);
    }

    public Function<VehiclePage, VehiclePage> doNotHaveVIN() {
        return VehiclePage::clickDoNotHaveVIN;
    }
}
