package cz.moneta.test.regression.channels.branch.archive;

import cz.moneta.dataprepare.CustomerDataPrepare;
import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.common.pages.TIS051_OBR001_ClientFinalSignatureConfirmationPage;
import cz.moneta.test.dsl.ufo.banka.pages.products.one.click.BAL015_S001_PackageDetail;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
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.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.Builders;
import org.junit.jupiter.api.Disabled;

import static cz.moneta.test.dsl.ufo.banka.tasks.accountenums.DebitCardFeePlan.FREE;
import static cz.moneta.test.dsl.ufo.banka.pages.main.BAL001_S008_SummaryStartDocumentsPage.ACCOUNT_NUMBER_KEY;
import static cz.moneta.test.harness.annotations.Environment.EDU;
import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@Disabled("Duplicates Cards team - CT-T9376")
@TestScenario(name = "Teller must be able to crate a new customer with BU Tom Plus and Debit card")
public class CreateNewCustomerWithBUTomPK extends CustomerDataPrepare {

    @TestCase(name = "Bank teller is able to login and create a new customer with BU Tom Plus and Debit card", environments = {TST1, PPE, EDU})
    @JiraTestCase(id = "POB-T18699")
    public void tcCreateNewCustomerWithTomAndDebitCard(Harness harness) {
        BankaTasks withBanka = harness.tasks().ufo().banka();
        String feePlan = "Tom Plus";
        String cardName = "Standard";
        String labelContent = "Debetní karta byla úspěšně založena";

        harness.withUfo()
                .openLoginPage()
                .then(withBanka.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(withBanka.search().findByCif(newCustomerCif))
                .then(withBanka.newProduct().createNewCurrentAccount(feePlan))
                .then(withBanka.newProduct().debitCardCommonPart(Long.parseLong(harness.get(ACCOUNT_NUMBER_KEY)), cardName, FREE))
                .clickContinueAndWaitUntilLoaded();

        UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible("OBR001_S001_B003")) {
            Builders.newWebFlowBuilder(TIS051_OBR001_ClientFinalSignatureConfirmationPage.class, endpoint, harness)
                    .continueToGeneralContractAndDispositionPage()
                    .continueToSummaryPage()
                    .checkTextLabelContent(labelContent)
                    .clickOk()
                    .onMainClientPage();
        } else {
            Builders.newWebFlowBuilder(BAL015_S001_PackageDetail.class, endpoint, harness)
                    .clickEndButtonToMainPage()
                    .selectFromListOfRequests()
                    .selectFirstApplication()
                    .clickToRequestDetailButton()
                    .clickPackageFoundationButtonAndSendToApproval()
                    .waitForLoader()
                    .continueToContractDocsPage()
                    .continueToGeneralContractAndDispositionPage()
                    .continueToSummaryPage()
                    .checkTextLabelContent(labelContent)
                    .clickOk()
                    .onPackageDetailPage()
                    .clickEndButtonToListOfRequestsPage()
                    .clickBackToMainClientPage();
        }
    }
}