package cz.moneta.test.dsl.auto.smartauto;

import cz.moneta.test.dsl.auto.smartauto.shared.*;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.SmartAutoEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.auto.smartauto.shared.CommonElements.LOADER_DIV;

public interface VehiclePage extends SmartAutoFlow<VehiclePage>, StoreAccessor {

    String CUSTOMER_PAGE_VALIDATION = "//span[contains(text(), 'Zákazník')]//following-sibling::span[contains(text(), '✓')]";
    String OTHERS_PAGE_VALIDATION = "//span[contains(text(), 'Ostatní')]//following-sibling::span[contains(text(), '✓')]";
    String VEHICLE_INFORMATION_BRAND = "//input[@name='vehicle.car.carBrand.name'][@value='%s']";
    String VEHICLE_INFORMATION_MODEL = "//input[@name='vehicle.car.carModelShort.name'][@value='%s']";
    String VEHICLE_INFORMATION_VIN_CHECKBOX = "//span[contains(text(), 'Vůz nemá VIN')]/../../../..";
    String VEHICLE_INFORMATION_VIN = "//input[@name='vehicle.chassisNumber']";
    String BUTTON_SEARCH = "(//span[text() = 'Vyhledat'])[1]";
    String FILTER_FUEL = "(//span[contains(text(), 'Palivo')])[1]/../..//following-sibling::div//input";
    String FILTER_FUEL_2 = "(//span[contains(text(), 'Palivo')])[2]/../..//following-sibling::div//input";
    String FILTER_BODYWORK = "(//span[contains(text(), 'Typ karosérie')])[1]/../..//following-sibling::div//input";
    String FILTER_GEARBOX = "(//span[contains(text(), 'Typ převodovky')])[1]/../..//following-sibling::div//input";
    String FILTER_DOORS = "(//span[contains(text(), 'Počet dveří')])[1]/../..//following-sibling::div//input";
    String BUTTON_FILTER_SEARCH = "//span[contains(text(), 'Filtry pro vyhledání vozidla')]/../../../../..//span[contains(text(), 'Vyhledat')]/..";
    String BUTTON_SEARCHED_VEHICLE = "//div[@class='vehicle-table-scrollbar-_sQil col-1TMxT']/div[1]/div";
    String BUTTON = "//button[contains(text(), '%s')]";
    String ENGINE_CAPACITY = "//input[@name='vehicle.specificCar.engineCapacity']";
    String ENGINE_KW = "//input[@name='vehicle.specificCar.engineKw']";
    String ENGINE_POWER = "//input[@name='enginePower']";
    String WEIGHT_TOTAL = "//input[@name='vehicle.specificCar.weightTotal']";
    String SEATS = "//input[@name='vehicle.specificCar.sittingPlaceNr']";
    String FUEL = "(//span[contains(text(), 'Palivo')])[2]/../..//following-sibling::div//input[@value='%s']";
    String MILEAGE = "//input[@name='vehicle.specificCar.travel']";
    String IMPORT_VEHICLE = "//span[contains(text(), 'Vozidlo z dovozu')]/../../../div/div/div/span/button//span[contains(text(), '%s')]/..";
    String DEALER_IS_OWNER = "//span[contains(text(), 'Dealer je majitelem vozidla')]/../../..//span[contains(text(), '%s')]/..";
    String DESCRIPTION = "//textarea[@name='vehicle.specificCar.description']";
    String OTHERS_PAGE = "//span[contains(text(), 'Ostatní')]";
    String BUTTON_TO_QUEUE = "//button[@data-testid=\"Button\"]/span[contains(text(),'Do fronty')]/..";
    String BUTTON_QUEUE_ACCEPT = "//button[contains(text(), 'Potvrdit')]";
    String MENU_SAVED = "(//span[contains(text(), 'Uložené')])[1]";

    //AGRO
    String AGRO_INFORMATION_BRAND = "//span[contains(text(), 'Výrobce')]/../following-sibling::div//input|//input[@name='vehicle.producer']";
    String AGRO_INFORMATION_MODEL = "//input[@name='vehicle.subjectDescription']";
    String AGRO_CAPACITY = "//input[@name='vehicle.withTp.engineCapacity']";
    String AGRO_ENGINE_KW = "//input[@name='vehicle.withTp.engineKw']";
    String AGRO_WEIGHT_TOTAL = "//input[@name='vehicle.withTp.weightTotal']";
    String AGRO_ACCESSORY = "//textarea[@name='vehicle.additionalThings']";
    String AGRO_NOTE = "//textarea[@name='vehicle.note']";
    String VEHICLE_DO_NOT_HAVE_VIN = "//input[@name='vehicle.withoutVin']";
    String AGRO_PGRLF_BUTTON_ACCEPT = "//label[@id='pgrlf']/span[contains(text(), 'PGRLF')]";
    String SUBSIDY_CONFIRM_CHECKBOX = "//span[contains(@class, 'f-checkbox2__text') and contains(., 'dotace')]";
    String ACCEPT_SUBSIDY_BUTTON = "//label[@id='pokus']";

    @CheckElementPresent(CUSTOMER_PAGE_VALIDATION)
    VehiclePage checkCustomerPageValidation();

    @CheckElementPresent(OTHERS_PAGE_VALIDATION)
    VehiclePage checkOthersPageValidation();

    @CheckElementPresent(VEHICLE_INFORMATION_BRAND)
    VehiclePage checkVehicleInformationBrand(Brand brand);

    @CheckElementPresent(VEHICLE_INFORMATION_MODEL)
    VehiclePage checkVehicleInformationModel(Model model);

    @Click(value = VEHICLE_INFORMATION_VIN_CHECKBOX, jsClick = true)
    VehiclePage clickVehicleWithoutVin();

    @TypeInto(FILTER_FUEL)
    VehiclePage typeFilterFuel(String filterFuel);

    @Wait(value = LOADER_DIV, until = Until.GONE)
    @TypeInto(value = FILTER_FUEL_2, clear = true)
    VehiclePage typeFilterFuel2(String filterFuel2);

    @Click(BUTTON)
    VehiclePage clickFilterFuel(FilterFuel filterFuel);

    @Click(BUTTON)
    VehiclePage clickFilterFuel2(FilterFuel filterFuel);

    @TypeInto(ENGINE_POWER)
    VehiclePage typeFilterPower(String filterPower);

    @Wait(explicitWaitSeconds = 2)
    @TypeInto(FILTER_BODYWORK)
    VehiclePage typeFilterBodywork(String filterBodywork);

    @Click(value = BUTTON, andWait = @Wait(explicitWaitSeconds = 2))
    VehiclePage clickFilterBodywork(FilterBodywork filterBodywork);

    @TypeInto(FILTER_GEARBOX)
    VehiclePage typeFilterGearbox(String filterGearbox);

    @Click(BUTTON)
    VehiclePage clickFilterGearbox(FilterGearbox filterGearbox);

    @TypeInto(FILTER_DOORS)
    VehiclePage typeFilterDoors(String filterDoors);

    @Click(BUTTON)
    VehiclePage clickFilterDoors(FilterDoors filterDoors);

    @Click(value = BUTTON_FILTER_SEARCH, andWait = @Wait(explicitWaitSeconds = 3), jsClick = true)
    VehiclePage clickSearchWithFilters();

    @Wait(explicitWaitSeconds = 4)
    @Click(BUTTON_SEARCHED_VEHICLE)
    VehiclePage clickSearchedVehicle(Model model);

    @CheckElementPresent(ENGINE_CAPACITY)
    VehiclePage checkEngineCapacity();

    @CheckElementPresent(ENGINE_KW)
    VehiclePage checkEngineKw();

    @CheckElementPresent(WEIGHT_TOTAL)
    VehiclePage checkWeightTotal();

    @CheckElementPresent(SEATS)
    VehiclePage checkSeats();

    @CheckElementPresent(FUEL)
    VehiclePage checkFuel(FilterFuel filterFuel);

    @TypeInto(value = MILEAGE, andWait = @Wait(value = LOADER_DIV, until = Until.GONE))
    VehiclePage typeMileage(int mileage);

    @TypeInto(value = DESCRIPTION, andWait = @Wait(value = LOADER_DIV, until = Until.GONE))
    VehiclePage typeDescription(String description);

    @Click(value = IMPORT_VEHICLE, jsClick = true)
    VehiclePage clickImportVehicle(ImportVehicle importVehicle);

    @Click(value = DEALER_IS_OWNER,jsClick = true)
    VehiclePage clickDealerIsOwner(DealerIsOwner dealerIsOwner);

    @Click(value = OTHERS_PAGE, jsClick = true)
    OthersPage clickOthersPage();

    @TypeInto(VEHICLE_INFORMATION_VIN)
    VehiclePage typeVehicleVin(String vin);

    @Click(BUTTON_SEARCH)
    VehiclePage clickSearchWithVin();

    @Click(value = BUTTON_TO_QUEUE, jsClick = true)
    VehiclePage clickToQueue();

    @Click(value = CommonElements.SAVE_CALCULATION_BUTTON, andWait = @Wait(value = CommonElements.SUCCESSFUL_SAVED_CALCULATION_MESSAGE, until = Until.VISIBLE), jsClick = true)
    VehiclePage clickSaveCalculation();

    @Click(MENU_SAVED)
    SavedCalculationsPage clickMenuSaved();

    //AGRO

    @CheckElementPresent(AGRO_INFORMATION_BRAND)
    VehiclePage checkAgroInformationBrand(Brand brand);

    @CheckElementPresent(AGRO_INFORMATION_MODEL)
    VehiclePage checkAgroInformationModel(Model model);

    @TypeInto(AGRO_CAPACITY)
    VehiclePage typeAgroCapacity(Integer capacity);

    @TypeInto(AGRO_ENGINE_KW)
    VehiclePage typeAgroEngineKw(Integer engineKw);

    @TypeInto(AGRO_WEIGHT_TOTAL)
    VehiclePage typeAgroWeightTotal(Integer weightTotal);

    @TypeInto(AGRO_ACCESSORY)
    VehiclePage typeAgroAccessory(String accessory);

    @TypeInto(AGRO_NOTE)
    VehiclePage typeAgroNote(String note);

    @Click(value = VEHICLE_DO_NOT_HAVE_VIN, jsClick = true)
    VehiclePage clickDoNotHaveVIN();

    @Click(value = AGRO_PGRLF_BUTTON_ACCEPT, jsClick = true, andWait = @Wait(explicitWaitSeconds = 1))
    VehiclePage clickAcceptPGRLF();

    @Click(value = SUBSIDY_CONFIRM_CHECKBOX, jsClick = true)
    VehiclePage clickAcceptSubsidyCheckbox();

    @Click(value = BUTTON_QUEUE_ACCEPT, jsClick = true)
    QueuePage clickQueueAccept();

    @Click(value = ACCEPT_SUBSIDY_BUTTON)
    VehiclePage clickSubsidyAcceptButton();

    @CustomAction()
    default VehiclePage scrollToAccept() {
        SmartAutoEndpoint endpoint = getEndpoint(SmartAutoEndpoint.class);
        endpoint.scrollIntoView(BUTTON_QUEUE_ACCEPT);
        return null;
    }

}