package cz.moneta.test.regression.channels.digital.ib.oldib.account.directdebit;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ib.utils.IbUtils;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenarioWithOrder;
import cz.moneta.test.harness.support.auth.Credentials;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Order;

import java.time.LocalDateTime;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenarioWithOrder(name = "Verify new direct debit order")
public class DirectDebitTest {
    private static final String MOBILE_KEY = "12341234";
    private static final String DIRECT_DEBIT_CONTENT = "Limit inkasa";
    private String birthNumber, clientID;
    private Credentials udebsCredentials;
    private LocalDateTime testExecutionStartTime;

    @BeforeAll
    public void getInfo(Harness harness) {
        birthNumber = harness.getConfig("IB.rc.direct-debit");
        clientID = harness.withUdebs().usersTable().getClientId(birthNumber);
        udebsCredentials = harness.withUdebs()
                .ib()
                .usernameAndPassword()
                .getUsernameAndPasswordByRc(birthNumber);
    }

    @Disabled
    @Order(1)
    @TestCase(name = "Create new direct debit order", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8262")
    void userWithCurrentAccount_shouldCreateNewDirectDebitOrder(Harness harness) {
        testExecutionStartTime = LocalDateTime.now();

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().loginWithDefaultMobileKeyAnd(udebsCredentials))
                .clickAccountsAndTransactions()
                .clickStandingOrders()
                .clicNewDirectDebidOrder()
                .clickFromAccountSelect()
                .getAndFillAccountFromNumber()
                .fillToAccountBank("3030")
                .fillUserNote("New incasso from automated test")
                .fillDirectDebitLimit("100")
                .fillEndDate("29.05.2040")
                .clickContinueButton()
                .typeSmsCode(MOBILE_KEY)
                .clickSign()
                .clickDirectDebitList();

        IbUtils.verifyTransactionStatus(harness, testExecutionStartTime, clientID, "333", 60);
    }

    @Disabled
    @Order(2)
    @TestCase(name = "Change of existing direct debit order", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8263")
    void userWithCurrentAccount_shouldChangeDirectDebitOrder(Harness harness) {
        testExecutionStartTime = LocalDateTime.now();

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().loginWithDefaultMobileKeyAnd(udebsCredentials))
                .clickAccountsAndTransactions()
                .clickStandingOrders()
                .clickChangeDirectDebit()
                .fillUserNote("Changed incasso from automated test")
                .fillDirectDebitLimit("200")
                .fillEndDate("28.11.2039")
                .clickContinueButton()
                .checkDirectDebitLimitPresence(DIRECT_DEBIT_CONTENT)
                .typeSmsCode(MOBILE_KEY)
                .clickSign()
                .clickDirectDebitList();

        IbUtils.verifyTransactionStatus(harness, testExecutionStartTime, clientID, "355", 60);
    }

    @Disabled
    @Order(3)
    @TestCase(name = "Delete existing direct debit order", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8264")
    void userWithCurrentAccount_shouldCancelDirectDebitOrder(Harness harness) {
        testExecutionStartTime = LocalDateTime.now();

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().loginWithDefaultMobileKeyAnd(udebsCredentials))
                .clickAccountsAndTransactions()
                .clickStandingOrders()
                .clickCancelDirectDebit()
                .checkDirectDebitLimitPresence(DIRECT_DEBIT_CONTENT)
                .typeSmsCode(MOBILE_KEY)
                .clickSign()
                .clickBack();

        IbUtils.verifyTransactionStatus(harness, testExecutionStartTime, clientID, "355", 60);
    }
}
