package cz.moneta.test.regression.channels.digital.ib.oldib.loan;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ib.loans.IbLoanData;
import cz.moneta.test.dsl.ib.utils.IbUtils;
import cz.moneta.test.dsl.util.DateUtils;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.data.client.NewClientWithCurrentAccountInformation;
import cz.moneta.test.dsl.util.task.ib.IbTasks;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;

import java.time.LocalDate;
import java.time.LocalDateTime;

import static cz.moneta.test.dsl.util.task.ib.IbTasks.DEFAULT_MOBILE_KEY;

@TestScenario(name = "TEA-601 – sjednání expres půjčky")
public class ArrangingExpressLoanTest {
    private Credentials credentials;
    private NewClientWithCurrentAccountInformation newClientData;
    private LocalDateTime testExecutionStartTime;
    private String clientId;

    @BeforeAll
    public void createClientWithBuAndIb(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        newClientData = harness.tasks()
                .dataPrepareTasks()
                .createNewFoCustomerWithCurrentAccountAndIbViaWso2(banker.getUsername());
        String birthNumber = newClientData.getClientData().birthNumber();

        credentials = harness.tasks().wso2().idm().getIbCredentialsByRC(birthNumber);

        clientId = harness.withUdebs()
                .usersTable()
                .getClientId(birthNumber);

        harness.withIlods().setScore("EXON01S2", birthNumber, null);
        harness.withIlods().setSegment("CUST_INC_VER", "POI_VALID_STRICTLY", birthNumber, null);
    }

    @Disabled
    @TestCase(name = "sjednání expres půjčky")
    public void arrangingExpressLoan(Harness harness) {
        IbTasks ibTasks = harness.tasks().ib();
        IbLoanData ibLoanData = new IbLoanData();
        testExecutionStartTime = LocalDateTime.now();
        ibLoanData.setEmail(RandomStringUtils.randomAlphabetic(6) + "@moneta.cz");
        ibLoanData.setOccupationType("manager/ředitel");
        ibLoanData.setEmploymentSince(DateUtils.getDateWithFormat(LocalDate.now().minusYears(5), "dd.MM.yyyy"));
        ibLoanData.setLoanAmount("5000");
        ibLoanData.setLoanTerms("6");
        ibLoanData.setSecondaryDocument("Cestovní pas");

        harness.withIB()
                .openLoginPage()
                .then(ibTasks.loginWithDefaultMobileKeyAnd(credentials))
                .clickLoans()
                .expressLoan()
                .setLoanAmount(ibLoanData.getLoanAmount())
                .setLoanTerms(ibLoanData.getLoanTerms())
                .getDataAndContinueToPersonalData(ibLoanData)
                .verifyLoanInformation(ibLoanData.getLoanAmount(), ibLoanData.getLoanTerms(), ibLoanData.getMonthlyInstallment(), ibLoanData.getIntRate())
                .setEmail(ibLoanData.getEmail())
                .selectSecondaryIdType(ibLoanData.getSecondaryDocument())
                .continueToAdditionalInformation()
                .continueToPermanentResidenceAndContactAddress()
                .continueToEmploymentAndIncomeExpenses()
                .backToPermanentResidenceAndContactAddress()
                .continueToEmploymentAndIncomeExpenses()
                .secOccupationType(ibLoanData.getOccupationType())
                .setEmploymentSince(ibLoanData.getEmploymentSince())
                .setEmploymentCount("1")
                .typeAverageIncome("50000")
                .typeAverageHomeIncome("80000")
                .typeOtherLoans("0")
                .typeOtherCosts("0")
                .typeWagesDeduction("0")
                .setNoneNoticePeriod()
                .agreementCheckboxAndContinue()
                .wantInsurance()
                .toInsure()
                .acceptAndContinue()
                .continueToSign()
                .typeMobileKey(DEFAULT_MOBILE_KEY)
                .sendLoanRequest()
                .loansOverview()
                .verifyExpressLoanData();

        IbUtils.verifyTransactionStatus(harness, testExecutionStartTime, clientId, "905", 60);
    }
}