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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.operations.client.ScoringDataPage;
import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_ClientDetailPage;
import cz.moneta.test.dsl.ufo.operations.search.*;

import java.util.function.Function;

public class SearchClientTasks {

    private final Harness harness;

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

    public Function<OPS001_S001_ClientSearchPageUfoOperations, STS701_S002_ClientDetailPage> byRc(String rc) {
        return start -> start.fillSearchInput(rc)
                .clickSearchClient()
                .onClientDetailsPage();
    }

    public Function<OPS001_S001_ClientSearchPageUfoOperations, STS701_S002_ClientDetailPage> searchClientByRc(String rc) {
        return start -> start.fillSearchInput(rc)
                .searchBy(SearchBy.BIRTH_NUMBER)
                .onClientDetailsPage();
    }

    public Function<OPS001_S001_ClientSearchPageUfoOperations, STS701_S002_ClientDetailPage> searchFOPClientByIco(String ico) {
        return start -> start.fillSearchInput(ico)
                .searchBy(SearchBy.ICO)
                .onClientDetailsPage();
    }

    public Function<OPS001_S001_ClientSearchPageUfoOperations, CIF708_S001_ListOfClientRepresentativesPage> searchPOClientByIco(String ico) {
        return start -> start.fillSearchInput(ico)
                .searchBy(SearchBy.ICO)
                .onListOfClientRepresentativesPage();
    }

    public Function<SCH704_S001_ClientSearchApRisk, ScoringDataPage> byAP(String ap) {
        return start -> start.fillAP(ap)
                .clickSearch()
                .clickAP(ap)
                .clickApprovalDataButton();
    }

    public Function<OPS001_S001_ClientSearchPageUfoOperations, CIF708_S001_ListOfClientRepresentativesPage> byIco(String ico) {
        return start -> start.fillSearchInput(ico)
                .searchBy(SearchBy.ICO)
                .onListOfClientRepresentativesPage();
    }

    public Function<OPS001_S001_ClientSearchPageUfoOperations, STS701_S002_ClientDetailPage> byCif(String cif) {
        return start -> start.fillSearchInput(cif)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage();
    }

    public Function<OPS001_S001_ClientSearchPageUfoOperations, STS701_S002_ClientDetailPage> searchClientByType(ClientType type, String rcIco) {
        if (type.equals(ClientType.FON)) {
            return start -> start.then(searchClientByRc(rcIco));
        } else if (type.equals(ClientType.FOP)) {
            return start -> start.then(searchFOPClientByIco(rcIco));
        } else {
            return start -> start.then(searchPOClientByIco(rcIco))
                    .clickContinueOnFirstClient();
        }
    }
}