package cz.moneta.test.regression.transactional.cards.retail.account.origination;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.CardBrand;
import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.NeedInsurance;
import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.ProductType;
import cz.moneta.test.dsl.ufo.banka.pages.main.codelists.Product;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.util.DateUtils;
import cz.moneta.test.dsl.util.data.client.Address;
import cz.moneta.test.dsl.util.data.client.Employer;
import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.harness.annotations.Defect;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.endpoints.testautomationdb.TestAutomationDbEndpoint;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.BeforeEach;

import static cz.moneta.test.dsl.ufo.banka.pages.cards.credit.CreditCardsAdvantages.ELECTRONICS;
import static cz.moneta.test.dsl.ufo.banka.pages.cards.credit.CreditCardsPromo.Zamestanec_MMB;
import static cz.moneta.test.dsl.util.credentials.Keys.ufo;
import static cz.moneta.test.harness.annotations.Environment.TST3;

@TestScenario(name = "ONB.RET.CC.27 - Retail CC - Account Onboarding - Employee MoneyCard Gold")
public class Employee_fromBranch_toBranch {

    NonClient nonClient;

    @BeforeEach
    void setUp(Harness harness, @Key(ufo.banka.banker) Credentials credentials) {
        nonClient = harness.data().newFVNonClientEmployee()
                .withNetMonthlyIncome(100000)
                .withHomeIncome(100000)
                .withOtherExpenses(30000)
                .withOtherLoanPayments(0)
                .withWageDeductions(0)
                .withIncomeSources("1")
                .withEmployer(Employer.builder()
                        .name("MONETA Money Bank, a.s.")
                        .ico("25672720")
                        .address(Address.builder()
                                .street("Vyskočilova")
                                .descriptiveNumber("1442")
                                .orientationNumber("1b")
                                .city("Praha")
                                .zip("14028")
                                .country("CZ")
                                .build())
                        .phoneNumber("224443636")
                        .build());

        String cifFo = harness.tasks().wso2().client().createCifFo(nonClient);
        String createdDateTime = DateUtils.getFormattedTodayDateTime("yyyy-MM-dd hh:mm:ss");
        harness.getEndpoint(TestAutomationDbEndpoint.class)
                .insertCreatedClientInfo(cifFo, nonClient.birthNumber(), null, createdDateTime, credentials.getUsername(), "MWF", null);

        harness.tasks().wso2().client().setGdprConsent(cifFo);
        harness.tasks().wso2().client().setCrAsTaxResidency(cifFo);

        BankaTasks bankaTasks = harness.tasks().ufo().banka();

        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .fillSearchTerm(cifFo)
                .clickSearchByCif()
                .onEmployeeClientPage()
                .clickContinueToCifMainPage()
                .clickElectronicDocumentation()
                .clickScanDocuments()
                .uploadAndAssignFakeId()
                .clickSkipButton()
                .onClientDocumentationPage()
                .clickEnd()
                .then(harness.tasks().ufo().banka().contactAddress().createContactAddress());

        harness.tasks().nasDb().insertUser(nonClient);
    }

    @Defect("Not Finished")
    @JiraTestCase(id = "FVP-T1513")
    @TestCase(name = "ONB.RET.CC.27 - Retail CC - Account Onboarding - Employee MoneyCard Gold", environments = {TST3})
    public void fromBranch_toBranch(Harness harness, @Key(ufo.banka.banker) Credentials credentials) {

        BankaTasks bankaTasks = harness.tasks().ufo().banka();

        harness.withUfo().openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findEmployeeByRC(nonClient.birthNumber()))
                .clickContinueToCifMainPage()
                .then(bankaTasks.newProduct().createNewCreditCard(nonClient,
                        ProductType.MONEYCARD_GOLD,
                        NeedInsurance.NO,
                        CardBrand.MC_GOLD,
                        ELECTRONICS,
                        Zamestanec_MMB,
                        "150000",
                        "30000",
                        "100000",
                        "100000"))
                .dismissClientNotificationAlert()
                .onSelectionOfSubmittedDocumentsPage()
                .selectIdCardRadio()
                .selectPassportRadio()
                .clickDocumentsCheckButton()
                .clickContinue()
                .onCreditCardApplicantInformationPage()
                .selectValidationStatus("údaj z OP")
                .selectNoticePeriod("Ne")
                .selectProbation("Ne")
                .selectOccupation("manager/ředitel")
                .fillIncomeSources(nonClient.incomeSources())
                .fillNetIncome(nonClient.netMonthlyIncome())
                .fillHomeIncome(nonClient.homeIncome())
                .fillOtherLoanPayments(nonClient.otherLoanPayments())
                .fillWageDeductions(nonClient.wageDeductions())
                .fillOtherExpenses(nonClient.otherExpenses())
                .selectSubmittedIncomeType("Potvrzení o příjmu")
                .checkValidCheckboxesAndContinue()
                .clickContinueButton()
                .clickApplicantSignatureCheckbox()
                .clickYes()
                .onScanDocumentsPage()
                .uploadAndAssignFakeIncomeConfirmation()
                .clickSkipButton()
                .onCreditCardScoringResultPage()
                .waitForStatusAndRefresh("SOUHLAS")
                .clickCreateProductAndPrintContract()
                .onSelectingApprovedVariantsPage()
                .clickToLoanAmountRadioButton()
                .typeIntoLoanAmount("150000")
                .clickSelectButtonToPreContractualPage()
                .clickContinueButtonToDraftContractCopyPage()
                .clickContinue()
                .onCreditCardRepaymentMethodConfirmation()
                .clickOk()
                .onCurrentAccountPage()
                .selectDistributionType("Elektronicky IB")
                .selectFeePlan("Tom účet")
                .clickConfirm()
                .onElectronicDistributionChannelCreationPage()
                .selectDistributionChannel("IB Heslo/MK")
                .clickContinueDismissAlertIfPresent()
                .onSignerPage()
                .chooseCitizen()
                .clickContinue()
                .onPreContractualInformationPage()
                .clickOnSignedAndContinueDocumentsProvidedToClientPage()
                .clickContinue()
                .onAccountDispositionOwnerPage()
                .clickOwnerOnly()
                .onSignaturePatternsEditPage()
                .clickSignaturePhysical()
                .onConfirmSignaturePage()
                .clickRightButton()
                .onConfirmationPage()
                .clickConfirmed()
                .onConfirmationOfSignaturePage()
                .clickClientAgreedAndSignedEmpowerment()
                .checkProductNotRecommended()
                .clickWithoutRecommendationAndDismissAlertIfvisible()
                .onAccountSelectionPage()
                .selectAccount(2)
                .clickSave()
                .onIbPasswordKeyPage()
                .typeDailyLimit("30000")
                .enterMobilePhoneNumber("602520104")
                .insertEnvelopeNumber()
                .clickContinueToSettingADCPage()
                .clickSave()
                .onDispositionPrintPage()
                .clickPrintEmpowermentNow()
                .onConfirmationPage()
                .clickOK()
                .continueToSignContractPage()
                .clickFirstSignerCheckbox()
                .clickYesButton()
                .clickOk()
                .clickContinue()
                .clickContinue()
                .fillPriceLimitInput("15000")
                .clickSaveContinueToSelectDisposition()
                .selectNothingAndGoBack()
                .clickSigned()
                .clickContinue()
                .onMainClientPage()
                .checkProductActive(Product.ADC_IB_MK_ACTIVE.getValue())
                .checkProductActive(ProductType.MONEYCARD_GOLD.getValue());

        harness.tasks().firstVision().verifyCreditCard(
                nonClient,
                "861",
                "680",
                "0",
                "1"
        );

        // FIXME .. or the other - workflow is different in the test script
    }
}
