package cz.moneta.test.regression.data.api;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.cagw.api.v1.external.product.cloan.application.ApplicationTokenResponse;
import cz.moneta.test.dsl.cagw.api.v1.external.product.cloan.application.Loan;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.ufo.banka.tasks.accountenums.CurrentAccountsEnum;
import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.harness.annotations.Defect;
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.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;

import java.util.Calendar;
import java.util.GregorianCalendar;

@TestScenario(name = "Create request via CA GW, verify it in ib")
public class PrivateApiCreateRequestViaCaGwTest {

    @Deprecated
    @Disabled("Disabled, to be reviewed.")
    @Defect("Nor finished, waiting for HRIS integration. TA-473")
    @TestCase(name = "End to end testcase create customer and then create payment via CA GW")
    public void tc_create_Request_with_private_api_ca_gw(Harness harness, @Key("ufo-banka-banker") Credentials credentials) {
        Calendar passportExpiry = GregorianCalendar.getInstance();
        BankaTasks bankaTasks = harness.tasks().ufo().banka();

        passportExpiry.set(2020, Calendar.JULY, 14);

        NonClient clientTestData = harness.data().newNonClient()
                .withEmail("123456@moneta.cz")
                .withPassportExpiryDateRaw(passportExpiry.getTime())
                .withPassportId("39729636");

        long applicationId = harness.withCaGw().api().v1().external().product().cbl().application()
                .prepareApplicationRequest()
                .withApplicationId("l7xx7877406788d04174b71e28cf5158a34f")
                .withApplicationSecret("e47267567a0344d4b5a1175e56e79196")
                .log("Application ID is: {}", ApplicationTokenResponse::getApplicationId)
                .loan(Loan.builder()
                        .termMonths(96)
                        .amount(150000)
                        .build())
                .client(harness.tasks().caGw().api().client()
                        .from(clientTestData))
                .send()
                .getApplicationId();

        Assertions.assertTrue(applicationId != 0, "ApplicationId from response is empty");

        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.newClient().create(clientTestData, credentials.getUsername()))
                .selectFromListOfRequests()
                .clickOpenRequestDetail()
                .onExpressScoringResultPage()
                .waitForStatusAndRefresh("PODMÍNĚNÝ SOUHLAS")
                .clickCreateAccounts()
                .onSelectApprovedVariantPage()
                .clickSecondVariant()
                .clickSelect()
                .onMegaExpressRequestPage()
                .clickFinishRequestButton()
                .clickContinueButtonToMegaExpressRequestPage()
                .clickFillInDocuments()
                .continueToClientRequiredDocumentsListPage()
                .clickAddDocument()
                .continueToConfirmationOfReceiptAddPage()
                .then(bankaTasks.expresTasks().fillConfirmationOfReceipt(clientTestData))
                .continueToClientRequiredDocumentsListPage()
                .clickContinue()
                .waitForStatusAndRefresh("SOUHLAS")
                .clickCreateAccounts()
                .onPreContractualInformationPrintedPage()
                .continueToPrintCopyOfContractProposalPage()
                .clickContinue()
                .onCurrentAccountPage()
                .selectFeePlan(CurrentAccountsEnum.GENIUS_FREE_FLEXI.getAccountName())
                .clickConfirm()
                .onPreContractInformationPage()
                .clickOnSigned()
                .continueToDispositionOwnerPage()
                .clickNotCreateNow()
                .clickSkipCreate()
                .onAddCodeOfRecommendedPersonPage()
                .checkProductNotRecommended()
                .clickWithoutRecommendationAndDismissAlertIfvisible()
                .onSuspendDispositionPrintPage()
                .clickPrintEmpowermentNow()
                .onClientFinalSignatureConfirmationPage()
                .continueToSecondBankerJoiningPage()
                .fillSurnameInput("Harness")
                .clickSearchButton()
                .selectBankerByLogin(credentials.getUsername());
    }
}
