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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.auto.smartauto.CustomerPage;
import cz.moneta.test.dsl.auto.smartauto.shared.*;

import java.util.function.Function;

public class IdentificationTasks {

    private final Harness harness;

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

    public Function<CustomerPage, CustomerPage> fillIdentification(IdentificationData identificationData) {
        return start -> start.clickFirstRepresentativeCountry()
                .chooseFirstRepresentativeCountry(identificationData.getCountry())
                .clickFirstIdentificationType()
                .chooseFirstIdentificationType(identificationData.getIdentificationType())
                .typeIdentificationIdNumber(identificationData.getIdentificationIdNumber())
                .clickFirstIdentificationIssuer()
                .chooseFirstIdentificationIssuer()
                .typeIdentificationIdValidity(identificationData.getIdentificationIdValidity());
    }

    public Function<CustomerPage, CustomerPage> fillSecondIdentification(IdentificationData identificationData) {
        return start -> start.clickFirstRepresentativeCountry()
                .typeSecondIdentificationIdNumber(identificationData.getIdentificationIdNumber())
                .typeSecondIdentificationIdValidity(identificationData.getIdentificationIdValidity());
    }

    public Function<CustomerPage, CustomerPage> fillIdentificationNotResident(IdentificationData identificationData) {
        return start -> start.clickFirstRepresentativeCountry()
                .chooseFirstRepresentativeCountry(identificationData.getCountry())
                .chooseStayType(identificationData.getStayType())
                .clickFirstIdentificationType()
                .chooseFirstIdentificationType(identificationData.getIdentificationType())
                .typeIdentificationIdNumber(identificationData.getIdentificationIdNumber())
                .clickFirstIdentificationIssuer()
                .chooseFirstIdentificationIssuer()
                .typeIdentificationIdValidity(identificationData.getIdentificationIdValidity());
    }
    public Function<CustomerPage, CustomerPage> fillFirstRepresentativeIdentification(ContactData contactData, IdentificationData identificationData) {
        return start -> start.clickCompanyRole()
                .chooseCompanyRole(identificationData.getCompanyRole())
                .typeFirstRepresentativeName(contactData.getName())
                .typeFirstRepresentativeSurname(contactData.getSurname())
                .typeFirstRepresentativeTitleBefore(contactData.getTitleBefore())
                .typeFirstRepresentativeTitleAfter(contactData.getTitleAfter())
                .clickFirstRepresentativeNationality()
                .chooseFirstRepresentativeNationality(identificationData.getNationality())
                .typeFirstRepresentativePin(identificationData.getPin().getValue())
                .lostFocus()
                .checkFirstRepresentativeBirthdate(identificationData.getBirthdate())
                .typeFirstRepresentativeBirthplace(identificationData.getBirthplace())
                .clickFirstRepresentativeCountry()
                .chooseFirstRepresentativeCountry(identificationData.getCountry())
                .clickFirstRepresentativeIdentificationType()
                .chooseFirstRepresentativeIdentificationType(identificationData.getIdentificationType())
                .typeFirstRepresentativeIdentificationIdNumber(identificationData.getIdentificationIdNumber())
                .clickFirstIdentificationIssuer()
                .chooseFirstIdentificationIssuer()
                .typeFirstRepresentativeIdentificationIdValidity(identificationData.getIdentificationIdValidity())
                .typeFirstRepresentativePhoneNumber(contactData.getPhoneNumber())
                .typeFirstRepresentativeOtherPhoneNumber(contactData.getOtherPhoneNumber())
                .typeFirstRepresentativeEmailAddress(contactData.getEmail())
                .typeFirstRepresentativePermanentAddress(contactData.getAddress().getValue())
                .clickFirstRepresentativePermanentAddress(contactData.getAddress())
                .typeFirstRepresentativeContactAddress(contactData.getAddress().getValue())
                .clickFirstRepresentativeContactAddress(contactData.getAddress());
    }

    public Function<CustomerPage, CustomerPage> fillFirstRepresentativeIdentificationNoRole(ContactData contactData, IdentificationData identificationData) {
        return start -> start.typeFirstRepresentativeName(contactData.getName())
                .typeFirstRepresentativeSurname(contactData.getSurname())
                .typeFirstRepresentativeTitleBefore(contactData.getTitleBefore())
                .typeFirstRepresentativeTitleAfter(contactData.getTitleAfter())
                .clickFirstRepresentativeNationality()
                .chooseFirstRepresentativeNationality(identificationData.getNationality())
                .typeFirstRepresentativePin(identificationData.getPin().getValue())
                .lostFocus()
                .checkFirstRepresentativeBirthdate(identificationData.getBirthdate())
                .typeFirstRepresentativeBirthplace(identificationData.getBirthplace())
                .clickFirstRepresentativeCountry()
                .chooseFirstRepresentativeCountry(identificationData.getCountry())
                .clickFirstRepresentativeIdentificationType()
                .chooseFirstRepresentativeIdentificationType(identificationData.getIdentificationType())
                .typeFirstRepresentativeIdentificationIdNumber(identificationData.getIdentificationIdNumber())
                .clickFirstIdentificationIssuer()
                .chooseFirstIdentificationIssuer()
                .typeFirstRepresentativeIdentificationIdValidity(identificationData.getIdentificationIdValidity())
                .typeFirstRepresentativePhoneNumber(contactData.getPhoneNumber())
                .typeFirstRepresentativeOtherPhoneNumber(contactData.getOtherPhoneNumber())
                .typeFirstRepresentativeEmailAddress(contactData.getEmail())
                .typeFirstRepresentativePermanentAddress(contactData.getAddress().getValue())
                .clickFirstRepresentativePermanentAddress(contactData.getAddress())
                .typeFirstRepresentativeContactAddress(contactData.getAddress().getValue())
                .clickFirstRepresentativeContactAddress(contactData.getAddress());
    }

    public Function<CustomerPage, CustomerPage> fillFirstRepresentativeIdentificationNotResident(ContactData contactData, IdentificationData identificationData) {
        return start -> start.clickCompanyRole()
                .chooseCompanyRole(identificationData.getCompanyRole())
                .typeFirstRepresentativeName(contactData.getName())
                .typeFirstRepresentativeSurname(contactData.getSurname())
                .typeFirstRepresentativeTitleBefore(contactData.getTitleBefore())
                .typeFirstRepresentativeTitleAfter(contactData.getTitleAfter())
                .clickFirstRepresentativeNationality()
                .chooseFirstRepresentativeNationality(identificationData.getNationality())
                .clickFirstRepresentativeStayType()
                .chooseFirstRepresentativeStayType(identificationData.getStayType())
                .typeFirstRepresentativePin(identificationData.getPin().getValue())
                .lostFocus()
                .checkFirstRepresentativeBirthdate(identificationData.getBirthdate())
                .typeFirstRepresentativeBirthplace(identificationData.getBirthplace())
                .clickFirstRepresentativeCountry()
                .chooseFirstRepresentativeCountry(identificationData.getCountry())
                .clickFirstRepresentativeIdentificationType()
                .chooseFirstRepresentativeIdentificationType(identificationData.getIdentificationType())
                .typeFirstRepresentativeIdentificationIdNumber(identificationData.getIdentificationIdNumber())
                .typeFirstRepresentativeIdentificationIdValidity(identificationData.getIdentificationIdValidity())
                .typeFirstRepresentativePhoneNumber(contactData.getPhoneNumber())
                .typeFirstRepresentativeOtherPhoneNumber(contactData.getOtherPhoneNumber())
                .typeFirstRepresentativeEmailAddress(contactData.getEmail())
                .typeFirstRepresentativePermanentAddress(contactData.getAddress().getValue())
                .clickFirstRepresentativePermanentAddress(contactData.getAddress())
                .typeFirstRepresentativeContactAddress(contactData.getAddress().getValue())
                .clickFirstRepresentativeContactAddress(contactData.getAddress());
    }

    public Function<CustomerPage, CustomerPage> fillSecondRepresentativeIdentification(ContactData contactData, IdentificationData identificationData) {
        return start -> start.clickSecondCompanyRole()
                .chooseSecondCompanyRole(identificationData.getCompanyRole())
                .typeSecondRepresentativeName(contactData.getName())
                .typeSecondRepresentativeSurname(contactData.getSurname())
                .typeSecondRepresentativeTitleBefore(contactData.getTitleBefore())
                .typeSecondRepresentativeTitleAfter(contactData.getTitleAfter())
                .clickSecondRepresentativeNationality()
                .chooseSecondRepresentativeNationality(identificationData.getNationality())
                .typeSecondRepresentativePin(identificationData.getPin().getValue())
                .lostFocus()
                .checkSecondRepresentativeBirthdate(identificationData.getBirthdate())
                .typeSecondRepresentativeBirthplace(identificationData.getBirthplace())
                .clickSecondRepresentativeCountry()
                .chooseSecondRepresentativeCountry(identificationData.getCountry())
                .clickSecondRepresentativeIdentificationType()
                .chooseSecondRepresentativeIdentificationType(identificationData.getIdentificationType())
                .typeSecondRepresentativeIdentificationIdNumber(identificationData.getIdentificationIdNumber())
                .typeSecondRepresentativeIdentificationIdValidity(identificationData.getIdentificationIdValidity())
                .typeSecondRepresentativePhoneNumber(contactData.getPhoneNumber())
                .typeSecondRepresentativeOtherPhoneNumber(contactData.getOtherPhoneNumber())
                .typeSecondRepresentativeEmailAddress(contactData.getEmail())
                .typeSecondRepresentativeContactAddress(contactData.getAddress().getValue())
                .clickSecondRepresentativeContactAddress(contactData.getAddress());
    }
}
