package cz.moneta.test.regression.channels.digital.ib.oldib.payment;

import cz.moneta.test.dsl.Harness;
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 cz.moneta.test.harness.annotations.JiraTestCase;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

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

@TestScenario(name = "Verify domestic payments")
public class DomesticPaymentOrderTest {
    private static final String DATE_FORMAT = "dd.MM.yyyy HH:mm:ss";
    private static final String TO_ACCOUNT_NUMBER = "123";
    private static final String TO_BANK_NUMBER = "0600";
    private static final String MOBILE_KEY = "12341234";
    private static final String VARIABLE_SYMBOL = "1234567890";
    private static final String CONSTANT_SYMBOL = "9876543210";
    private static final String PAYMENT_VALUE = "1";

    @Disabled
    @TestCase(name = "Go to current account and make standard domestic payment", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8237")
    void userWithCurrentAccount_shouldCreateNewStandardDomesticPayment(Harness harness, @Key("ib.client") Credentials credentials) {
        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().loginWithDefaultMobileKeyAnd(credentials))
                .clickAccountsAndTransactions()
                .clickNewDomesticPaymentOrder()
                .clickFromAccountSelect()
                .fillToAccountNumber(TO_ACCOUNT_NUMBER)
                .fillToAccountBank(TO_BANK_NUMBER)
                .fillAmount(PAYMENT_VALUE)
                .fillVariableSymbol(VARIABLE_SYMBOL)
                .fillConstantSymbol(CONSTANT_SYMBOL)
                .fillNoteForRecipient("My standard payment for You")
                .clickStandardPayment()
                .fillNote("My standard payment")
                .clickCategorySelect()
                .clickContinueButton()
                .clickSign()
                .typeSmsCode(MOBILE_KEY)
                .clickSend()
                .clickListPaymentOrders();
    }

    @Disabled
    @TestCase(name = "Go to current account and make instant domestic payment", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8268")
    void userWithCurrentAccount_shouldCreateNewInstantDomesticPayment(Harness harness, @Key("ib.client") Credentials credentials) {
        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().loginWithDefaultMobileKeyAnd(credentials))
                .clickAccountsAndTransactions()
                .clickNewDomesticPaymentOrder()
                .clickFromAccountSelect()
                .fillToAccountNumber(TO_ACCOUNT_NUMBER)
                .fillToAccountBank(TO_BANK_NUMBER)
                .fillAmount(PAYMENT_VALUE)
                .fillVariableSymbol(VARIABLE_SYMBOL)
                .fillConstantSymbol(CONSTANT_SYMBOL)
                .fillNoteForRecipient("My instant payment for You")
                .clickInstantPayment()
                .fillNote("My instant payment")
                .clickCategorySelect()
                .clickContinueButton()
                .clickSign()
                .typeSmsCode(MOBILE_KEY)
                .clickSend()
                .clickListPaymentOrders();
    }

    @Disabled
    @TestCase(name = "Go to current account and make priority domestic payment", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8269")
    void userWithCurrentAccount_shouldCreateNewPriorityDomesticPayment(Harness harness, @Key("ib.client") Credentials credentials) {
        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().loginWithDefaultMobileKeyAnd(credentials))
                .clickAccountsAndTransactions()
                .clickNewDomesticPaymentOrder()
                .clickFromAccountSelect()
                .fillToAccountNumber(TO_ACCOUNT_NUMBER)
                .fillToAccountBank("0800")
                .fillAmount(PAYMENT_VALUE)
                .fillVariableSymbol(VARIABLE_SYMBOL)
                .fillConstantSymbol(CONSTANT_SYMBOL)
                .fillNoteForRecipient("My priority payment for You")
                .clickPriorityPayment()
                .fillNote("My priority payment")
                .clickCategorySelect()
                .clickContinueButton()
                .clickSign()
                .typeSmsCode(MOBILE_KEY)
                .clickSend()
                .clickListPaymentOrders();
    }

    @Disabled
    @TestCase(name = "Go to current account and make transfer between own CZK accoutns", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8361")
    void userWithTwoCurrentAccount_shouldCreateNewTransferBetweenOwnAccounts(Harness harness) {
        String rcOfClientWithTwoCZKacc = harness.getConfig("IB.rc.user-with-two-CZK-accounts");

        Credentials udebsCredentials = harness.withUdebs()
                .ib()
                .usernameAndPassword()
                .getUsernameAndPasswordByRc(rcOfClientWithTwoCZKacc);

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().loginWithDefaultMobileKeyAnd(udebsCredentials))
                .clickAccountsAndTransactions()
                .clickNewDomesticPaymentOrder()
                .clickTransferBetweenOwnAccounts()
                .clickFromFirstAccountSelect()
                .clickToSecondOwnAccountSelect()
                .fillAmount(PAYMENT_VALUE)
                .fillNote("Transfer Between Own Accounts")
                .clickContinueButton()
                .clickSignTransferBetweenOwnAcc()
                .clickListPaymentOrders();
    }

    @Disabled
    @TestCase(name = "Go to current account and make mass payment", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8433")
    void userWithTwoCurrentAccount_shouldCreateMassPayment(Harness harness) {
        String rcOfClientMassPayment = harness.getConfig("IB.rc.mass-payment");
        String clientID = harness.withUdebs().usersTable().getClientId(rcOfClientMassPayment);
        LocalDateTime nowDateTime = LocalDateTime.now();
        LocalDateTime plusThreeMinutesDateTime = nowDateTime.plusMinutes(3);
        String fromDateTime = DateTimeFormatter.ofPattern(DATE_FORMAT).format(nowDateTime);
        String toDateTime = DateTimeFormatter.ofPattern(DATE_FORMAT).format(plusThreeMinutesDateTime);

        Credentials udebsCredentials = harness.withUdebs()
                .ib()
                .usernameAndPassword()
                .getUsernameAndPasswordByRc(rcOfClientMassPayment);

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().loginWithDefaultMobileKeyAnd(udebsCredentials))
                .clickAccountsAndTransactions()
                .clickNewDomesticPaymentOrder()
                .clickMassPayment()
                .clickFromFirstAccountMassPaymentSelect()
                .fillToAccountNumber(TO_ACCOUNT_NUMBER)
                .fillToAccountBank(TO_BANK_NUMBER)
                .fillAmount(PAYMENT_VALUE)
                .fillVariableSymbol(VARIABLE_SYMBOL)
                .fillConstantSymbol(CONSTANT_SYMBOL)
                .fillNoteForRecipient("Mass payment")
                .clickContinueButtonMassPayment()
                .clickAddPaymentOrder()
                .fillToAccountNumber(TO_ACCOUNT_NUMBER)
                .fillToAccountBank(TO_BANK_NUMBER)
                .fillAmount(PAYMENT_VALUE)
                .fillVariableSymbol(VARIABLE_SYMBOL)
                .fillConstantSymbol(CONSTANT_SYMBOL)
                .fillNoteForRecipientMassPayment("Mass payment 2")
                .clickMassPaymentContinueButton()
                .clickSignMassPayment()
                .typeSmsCodeMassPayment(MOBILE_KEY)
                .clickSendMassPayment()
                .clickListMassPaymentOrders();

        String transactionStatus = harness.withUdebs()
                .transactionsClient()
                .getLastTransactionStatus(clientID, "340", "15", fromDateTime, toDateTime, 15, "60");

        Assertions.assertEquals("60", transactionStatus, "Verify that the mass payment transaction is in the correct statusID");
    }

    @Disabled
    @TestCase(name = "Go to current account and list waiting payment order", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8238")
    void userWithCurrentAccount_shouldSeeListOfWaitingPaymentOrders(Harness harness, @Key("ib.client") Credentials credentials) {
        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().loginWithDefaultMobileKeyAnd(credentials))
                .clickAccountsAndTransactions();
    }
}


