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.tasks.BankaTasks;
import cz.moneta.test.dsl.ufo.banka.tasks.payment.PaymentTasks;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import org.junit.jupiter.api.Disabled;

import static cz.moneta.test.dsl.ufo.banka.pages.common.pages.OBR001_S001_PrintInstructionPage.ROOT_ID_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
@TestScenario(name = "Create new direct debit")
public class CreateNewDirectDebit extends CustomerDataPrepare {

    @TestCase(name = "Create new direct debit", environments = {TST1, PPE, EDU})
    @JiraTestCase(id = "POB-T19491")
    public void tc_create_new_directs_debit(Harness harness) {
        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        PaymentTasks paymentTasks = harness.tasks().ufo().banka().payment();
        String receiverBankAccount = "115";
        String receiverBankCode = "0300";
        String amount = "1";
        String changeAmount = "2";
        String receiverAccountNameInput = "a";
        String changeTitle = "Zmenen nazev";

        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByCif(newCustomerCif))
                .then(bankaTasks.newProduct().createNewCurrentAccount("Tom Plus"))
                .checkProductActive("Běžný účet")
                .openCurrentAccountDetailPage()
                .openListOfDirectDebitsPage()
                .clickCreateButton()
                .checkNotSavingNotFilledForm()
                .fillReceiverAccountNumber(receiverBankAccount)
                .fillReceiverAccountBankCode(receiverBankCode)
                .fillAmount(amount)
                .selectPeriod("Měsíční")
                .fillReceiverAccountName(receiverAccountNameInput)
                .clickSaveToPrint()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onPrintInstructionPage()
                .storeRootId()
                .clickCenterButton()
                .onClientChargedPage()
                .clickOkToListOfAuthorizationForDirectDebitsPage()
                .checkAuthorizationForDirectDebitValid(harness.get(ROOT_ID_KEY))
                .clickFirstDirectDebit()
                .then(paymentTasks.checkDirectDebitChange(changeTitle, changeAmount, String.valueOf(Integer.parseInt(harness.get(ROOT_ID_KEY)) + 1)))
                .clickFirstDirectDebit()
                .then(paymentTasks.deleteAuthorizationForDirectDebitAndCheckStatus(String.valueOf(Integer.parseInt(harness.get(ROOT_ID_KEY)) + 2)));
    }
}
