package cz.moneta.test.dsl.util.task.ufo.operations;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.ZKU704_S001_ChangeContactData;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;


import java.util.function.Function;

public class ChangeContactAddressTasks {
    private final Harness harness;

    public ChangeContactAddressTasks(Harness harness) {
        this.harness = harness;
    }

    public Function<ZKU704_S001_ChangeContactData, ZKU704_S001_ChangeContactData> changeAddressByCondition() {
        if (harness.getEndpoint(UfoEndpoint.class).getText(ZKU704_S001_ChangeContactData.ADDRESS).equals("Na Kameni")) {
            return start -> start
                    .then(harness.tasks().ufo().operations().changeContactAddressTasks().changeAnotherAddress());
        } else{
            return start -> start
                    .then(harness.tasks().ufo().operations().changeContactAddressTasks().changeAddress());
        }
    }

    public Function<ZKU704_S001_ChangeContactData, ZKU704_S001_ChangeContactData> changeAddress() {
        return page -> page
                .clickSaveAddress()
                .typePartAddress("Na Kameni 44")
                .clickSearchAddress()
                .clickChooseAddress()
                .clickSaveAddress();
    }
    public Function<ZKU704_S001_ChangeContactData, ZKU704_S001_ChangeContactData> changeAnotherAddress() {
        return page -> page
                .clickSaveAddress()
                .typePartAddress("Dlouhá 928")
                .clickSearchAddress()
                .clickChooseAddress()
                .clickSaveAddress();
    }

    public Function<ZKU704_S001_ChangeContactData, ZKU704_S001_ChangeContactData> changeToWrongAddress() {
        return page -> page
                .fillStreet("Dlouhá")
                .fillDescriptionNumber("928")
                .fillOrientationNumber("1a")
                .fillPostalCode("110 00")
                .fillDistrictNumber("Staré Město")
                .fillCity("Praha")
                .clickSaveAddress()
                .assertWarning("Nebyl nalezen žádný adresný bod, prosím o konkrétnější specifikaci adresy !")
                .closeSearchAddress();
    }

}
