package cz.moneta.test.dsl.ufo.banka.pages.loans;

import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.NKK007_S001_ClipRequestPage;
import cz.moneta.test.dsl.ufo.banka.pages.income.PIM001_S001_IncomeEditPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.client.settings.ODS003_S001_AddCodeOfRecommendedPersonPage;
import cz.moneta.test.dsl.ufo.operations.shared.SharedElements;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;
import org.openqa.selenium.WebElement;

import java.util.List;

import static cz.moneta.test.dsl.ufo.banka.pages.loans.NEP002_S001_ApplicantPage.CONTINUE_BUTTON;
import static cz.moneta.test.dsl.ufo.banka.pages.loans.NEP002_S001_ApplicantPage.NEP002_S001_PAGE_LABEL_XPATH;

@Wait(value = NEP002_S001_PAGE_LABEL_XPATH, by = Lookup.XPATH)
@Wait(CONTINUE_BUTTON)
public interface NEP002_S001_ApplicantPage extends WebFlow<NEP002_S001_ApplicantPage>, NEP002_S001_ApplicantPageTransitions, SharedElements, StoreAccessor {

    String NEP002_S001_PAGE_LABEL_XPATH = "//div[text()='NEP002_S001']";
    String CONTINUE_BUTTON = "NEP002_S001_B004";
    String NOTICE_PERIOD_SELECT = "NEP002_S001_C015";
    String TRIAL_PERIOR_SELECT = "NEP002_S001_C016";
    String NET_MONTHLY_INCOME_3M_INPUT = "NEP002_S001_E411";
    String TOTAL_HOUSEHOLD_INCOME_INPUT = "NEP002_S001_E441";
    String PAYMENTS_OUTSIDE_MMB_INPUT = "NEP002_S001_E045";
    String HOUSEHOLD_EXPENSES_INPUT = "NEP002_S001_E041";
    String OCCUPATION_SELECT = "NEP002_S001_C013";
    String ALLOWANCES_INPUT = "NEP002_S001_E461";
    String MONTHLY_PAYMENTS_INPUT = "NEP002_S001_E043";
    String OTHER_LIVING_EXPENSES_INPUT = "NEP002_S001_E044";
    String NECESSARY_MONTHLY_EXPENSES_INPUT = "NEP002_S001_E046";
    String INCOME_SOURCE_COUNT_INPUT = "NEP002_S001_E401";
    String POP_SELECT = "NEP002_S001_C005";
    String POP_CONTINUE_BUTTON = "NEP002_S001_B010";
    String POP_CHECKBOX_GENERAL_XPATH = "//div[@id='NEP002_S001_FB001']//input [@value='%s']";
    String HOUSEHOLD_INCOME_INPUT = "NEP002_S001_E055";
    String TELCO_YES_RADIO = "NEP002_S001_R001_1";
    String MARITAL_STATUS_VERIFICATION_SOURCE_SELECT = "NEP002_S001_C011";
    String MOBILE_NUMBER_EMPLOYMENT = "NEP002_S001_E371";
    String REGISTRATION_NUMBER_SELECT = "NEP002_S001_C481";
    String REGISTRATION_NUMBER_REASON_SELECT = "NEP002_S001_C008";
    String REGISTRATION_NUMBER_CONFIRM_BUTTON = "NEP002_S001_B007";
    String REGISTRATION_NUMBER_COMMENT_INPUT = "NEP002_S001_M001";
    String EMPLOYMENT_END_DATE = "NEP002_S001_E385";
    String HOUSING_EXPENSES_INPUT = "NEP002_S001_E029";
    String FIRST_INCOME_CHECKBOX = "NEP002_S001_G003-0";
    String INCOME_CHECKBOX = "//input[contains(@id, 'NEP002_S001_G003-')]";
    String EDIT_INCOME_BUTTON = "NEP002_S001_B014";
    String SPECIAL_RELATIONS_WITH_BANK_SELECT = "NEP002_S001_C491";
    String COMMENTARY_INPUT = "NEP002_S001_M002";
    String BIRTH_NUMBER_DIV = "NEP002_S001_L011";
    String LAST_NAME_DIV = "NEP002_S001_L021";
    String FIRST_NAME_DIV = "NEP002_S001_L031";
    String MARITAL_STATUS_DIV = "NEP002_S001_L121";
    String HOUSING_TYPE_DIV = "NEP002_S001_L091";
    String EDUCATION_DIV = "NEP002_S001_L101";
    String NATIONALITY_DIV = "NEP002_S001_L071";
    String FIRST_ID_CARD_TYPE_DIV = "NEP002_S001_L261";
    String FIRST_ID_CARD_NUMBER_DIV = "NEP002_S001_L051";
    String FIRST_ID_CARD_EXPIRATION_DATE_DIV = "NEP002_S001_L061";
    String SECOND_ID_CARD_TYPE_DIV = "NEP002_S001_L027";
    String SECOND_ID_CARD_NUMBER_DIV = "NEP002_S001_L028";
    String SECOND_ID_CARD_EXPIRATION_DATE_DIV = "NEP002_S001_L032";
    String ADDRESS_DIV = "NEP002_S001_L130";
    String CORRESPONDENCE_ADDRESS_DIV = "NEP002_S001_L068";
    String LANDLINE_DIV = "NEP002_S001_L191";
    String MOBILE_PHONE_DIV = "NEP002_S001_L201";
    String EMAIL_DIV = "NEP002_S001_L301";
    String DEPENDANTS_NUMBER_DIV = "NEP002_S001_L077";
    String SAME_HOUSEHOLD_SELECT = "NEP002_S001_C640";

    @CustomAction
    default NEP002_S001_ApplicantPage clickPopCheckbox(PopCheckboxes checkboxType) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String path = String.format(POP_CHECKBOX_GENERAL_XPATH, checkboxType.getValue());
        endpoint.click(() -> path, Lookup.XPATH);
        return null;
    }

    @Select(NOTICE_PERIOD_SELECT)
    NEP002_S001_ApplicantPage selectNoticePeriod(String noticePeriod);

    @Select(TRIAL_PERIOR_SELECT)
    NEP002_S001_ApplicantPage selectTrialPeriod(String trialPeriod);

    @TypeInto(value = NET_MONTHLY_INCOME_3M_INPUT, clear = true)
    NEP002_S001_ApplicantPage fillNetMonthlyIncome(int netMonthlyIncome);

    @TypeInto(value = MOBILE_NUMBER_EMPLOYMENT, clear = true)
    NEP002_S001_ApplicantPage fillMobileNumberEmployment(String mobileNumberEmployment);

    @Select(OCCUPATION_SELECT)
    NEP002_S001_ApplicantPage selectOccupation(String occupation);

    @TypeInto(value = ALLOWANCES_INPUT, clear = true)
    NEP002_S001_ApplicantPage fillAllowances(int allowances);

    @TypeInto(value = MONTHLY_PAYMENTS_INPUT, clear = true)
    NEP002_S001_ApplicantPage fillMonthlyPayments(int monthlyPayments);

    @TypeInto(value = PAYMENTS_OUTSIDE_MMB_INPUT, clear = true)
    NEP002_S001_ApplicantPage fillPaymentsOutsideMMB(int paymentsOutsideMMB);

    @TypeInto(value = HOUSEHOLD_INCOME_INPUT, clear = true)
    NEP002_S001_ApplicantPage fillHouseholdIncome(int householdIncome);

    @TypeInto(value = TOTAL_HOUSEHOLD_INCOME_INPUT, clear = true)
    NEP002_S001_ApplicantPage fillTotalHouseholdIncome(int totalHouseholdIncome);

    @TypeInto(value = OTHER_LIVING_EXPENSES_INPUT, clear = true)
    NEP002_S001_ApplicantPage fillOtherExpenses(int otherExpenses);

    @TypeInto(value = NECESSARY_MONTHLY_EXPENSES_INPUT, clear = true)
    NEP002_S001_ApplicantPage fillOtherMonthlyExpenses(int necessaryMonthlyExpenses);

    @TypeInto(value = INCOME_SOURCE_COUNT_INPUT, clear = true)
    NEP002_S001_ApplicantPage fillIncomeSourceCount(int incomeSourceCount);

    @Select(MARITAL_STATUS_VERIFICATION_SOURCE_SELECT)
    NEP002_S001_ApplicantPage selectMaritalStatusVerificationSource(String maritalStatusVerificationSource);

    @Click(TELCO_YES_RADIO)
    NEP002_S001_ApplicantPage clickTelcoYes();

    @Select(value = POP_SELECT,
            andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    NEP002_S001_ApplicantPage selectPOP(String pop);

    @Click(POP_CONTINUE_BUTTON)
    NEP002_S001_ApplicantPage clickPoPContinue();

    @Click(CONTINUE_BUTTON)
    NEP002_S001_ApplicantPageTransitions clickContinue();

    @Click(CONTINUE_BUTTON)
    ODS003_S001_AddCodeOfRecommendedPersonPage clickContinueToSigningActionPage();

    @Select(REGISTRATION_NUMBER_SELECT)
    NEP002_S001_ApplicantPage selectRegistrationNumber(String registrationNumber);

    @Select(REGISTRATION_NUMBER_REASON_SELECT)
    NEP002_S001_ApplicantPage selectRegistrationNumberReason(String registrationNumberReason);

    @Select(SPECIAL_RELATIONS_WITH_BANK_SELECT)
    NEP002_S001_ApplicantPage selectSpecialRelationsWithBank(String relationshipWithBank);

    @TypeInto(REGISTRATION_NUMBER_COMMENT_INPUT)
    NEP002_S001_ApplicantPage fillRegistrationNumberComment(String comment);

    @Click(REGISTRATION_NUMBER_CONFIRM_BUTTON)
    NEP002_S001_ApplicantPage clickRegistrationNumberOkButton();

    @TypeInto(EMPLOYMENT_END_DATE)
    NEP002_S001_ApplicantPage fillEmploymentEndDate(String date);

    @TypeInto(value = HOUSING_EXPENSES_INPUT, clear = true)
    NEP002_S001_ApplicantPage fillHousingExpenses(int housingExp);

    @TypeInto(value = HOUSEHOLD_EXPENSES_INPUT, clear = true)
    NEP002_S001_ApplicantPage fillHouseholdExpenses(int householdExp);

    @Click(FIRST_INCOME_CHECKBOX)
    NEP002_S001_ApplicantPage selectFirstIncome();

    @Click(EDIT_INCOME_BUTTON)
    PIM001_S001_IncomeEditPage clickEditIncomeButton();

    @Wait(explicitWaitSeconds = 3)
    @Click(CONTINUE_BUTTON)
    NEP001_S004_ApplicationDataPage continueToExpressLoanDateApplication();

    @Click(CONTINUE_BUTTON)
    NKK007_S001_ClipRequestPage clickContinueToClipRequest();

    @TypeInto(COMMENTARY_INPUT)
    NEP002_S001_ApplicantPage fillCommentary(String commentary);

    @CheckElementContent(BIRTH_NUMBER_DIV)
    NEP002_S001_ApplicantPage checkBirthNumber(String birthNumber);

    @CheckElementContent(LAST_NAME_DIV)
    NEP002_S001_ApplicantPage checkLastName(String lastName);

    @CheckElementContent(FIRST_NAME_DIV)
    NEP002_S001_ApplicantPage checkFirstName(String firstName);

    @CheckElementContent(MARITAL_STATUS_DIV)
    NEP002_S001_ApplicantPage checkMaritalStatus(String maritalStatus);

    @CheckElementContent(HOUSING_TYPE_DIV)
    NEP002_S001_ApplicantPage checkHousingType(String housingType);

    @CheckElementContent(EDUCATION_DIV)
    NEP002_S001_ApplicantPage checkEducation(String education);

    @CheckElementContent(NATIONALITY_DIV)
    NEP002_S001_ApplicantPage checkNationality(String nationality);

    @CheckElementContent(FIRST_ID_CARD_TYPE_DIV)
    NEP002_S001_ApplicantPage checkFirstIdCardType(String firstIdCardType);

    @CheckElementContent(FIRST_ID_CARD_NUMBER_DIV)
    NEP002_S001_ApplicantPage checkFirstIdCardNumber(String firstIdCardNumber);

    @CheckElementContent(FIRST_ID_CARD_EXPIRATION_DATE_DIV)
    NEP002_S001_ApplicantPage checkFirstIdCardExpirationDate(String firstIdCardExpirationDate);

    @CheckElementContent(SECOND_ID_CARD_TYPE_DIV)
    NEP002_S001_ApplicantPage checkSecondIdCardType(String secondIdCardType);

    @CheckElementContent(SECOND_ID_CARD_NUMBER_DIV)
    NEP002_S001_ApplicantPage checkSecondIdCardNumber(String secondIdCardNumber);

    @CheckElementContent(SECOND_ID_CARD_EXPIRATION_DATE_DIV)
    NEP002_S001_ApplicantPage checkSecondIdCardExpirationDate(String secondIdCardExpirationDate);

    @CheckElementContent(ADDRESS_DIV)
    NEP002_S001_ApplicantPage checkAddress(String address);

    @CheckElementContent(CORRESPONDENCE_ADDRESS_DIV)
    NEP002_S001_ApplicantPage checkCorrespondenceAddress(String correspondenceAddress);

    @CheckElementContent(LANDLINE_DIV)
    NEP002_S001_ApplicantPage checkLandline(String landline);

    @CheckElementContent(MOBILE_PHONE_DIV)
    NEP002_S001_ApplicantPage checkMobilePhone(String mobilePhone);

    @CheckElementContent(EMAIL_DIV)
    NEP002_S001_ApplicantPage checkEmail(String email);

    @CheckElementContent(DEPENDANTS_NUMBER_DIV)
    NEP002_S001_ApplicantPage checkDependantsNumber(String dependantsNumber);

    @Select(SAME_HOUSEHOLD_SELECT)
    NEP002_S001_ApplicantPage isSameHouseHold(String sameHouseHold);

    @CustomAction
    default NEP002_S001_ApplicantPage selectEachIncome() {
        UfoEndpoint ep = getEndpoint(UfoEndpoint.class);
        List<WebElement> incomeCheckboxes = ep.findAndGetListOfElements(INCOME_CHECKBOX, Lookup.XPATH);
        for (WebElement incomeCheckbox :
                incomeCheckboxes) {
            incomeCheckbox.click();
        }
        return null;
    }
}
