package cz.moneta.test.regression.channels.digital.ib.newib.settings;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.newib.tasks.NewIbTasks;
import cz.moneta.test.dsl.newib.util.PaymentFormData;
import cz.moneta.test.harness.annotations.Environment;
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.text.SimpleDateFormat;

@TestScenarioWithOrder(name = "Settings - Template creation tests")
public class TemplatesTest {
    Credentials clientCredentials;
    PaymentFormData formData;

    private String getDate() {
        return new SimpleDateFormat("MM/dd-HH:mm:ss").format(new java.util.Date());
    }

    @BeforeAll
    public void getCredentials(Harness harness) {
        String clientBirthNumber = harness.getConfig("nib.rc.templates");
        String fromAccountNumber = harness.getConfig("nib.fromaccount.templates");

        clientCredentials = harness.tasks()
                .udebs()
                .findCredentialsByRC(clientBirthNumber);

        formData = PaymentFormData.builder()
                .templateName(getDate())
                .prefixAccountNumber("19")
                .recipientAccountNumber("19019")
                .bankCode("3030")
                .amount("222")
                .variableSymbol("1111")
                .constantSymbol("2222")
                .specificSymbol("3333")
                .recipientMessage("recipient message")
                .myNote("note for me")
                .category("Bydlení")
                .iban("BE62510007547061")
                .currency("PLN")
                .typeOfCharge("SHA")
                .recipientName("Autotest Test")
                .recipientAddressStreet("Autotest street")
                .recipientAddressCity("Autotest city")
                .recipientAddressCountry("AR - Argentina")
                .recipientMessage("autotest message for recipient")
                .confirmationEmail("autotest@mmb.cz")
                .build();
    }

    @Disabled
    @Order(1)
    @TestCase(name = "Domestic template create", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "NIB-T1593")
    public void domesticTemplateCreation(Harness harness) {
        NewIbTasks newIbTasks = harness.tasks().newIb();

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.setDomesticTemplateForm(formData))
                .then(newIbTasks.checkTemplateAndDeleteCreatedOne(formData));
    }

    @Disabled
    @Order(2)
    @TestCase(name = "Foreign template create", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "NIB-T1594")
    public void foreignTemplateCreation(Harness harness) {
        NewIbTasks newIbTasks = harness.tasks().newIb();

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.setForeignTemplateForm(formData))
                .then(newIbTasks.checkForeignTemplateAndDeleteCreatedOne(formData));
    }
}
