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.Order;

import static cz.moneta.test.harness.support.data.GeneratorType.SIPO;

@TestScenarioWithOrder(name = "Settings - SIPO creation test")
public class SipoSettingsTest {
    Credentials clientCredentials;
    PaymentFormData formData;

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

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

        formData = PaymentFormData.builder()
                .fromAccountNumber(fromAccountNumber)
                .limit("100")
                .lastDateOfPayment("31. 3. 2045")
                .build();
    }

    @Order(1)
    @TestCase(name = "SIPO creation test - via Settings", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9341")
    public void sipoCreationEditDeleteViaSettings(Harness harness) {
        String rawSipo = harness.generate(SIPO);
        harness.log("Generated SIPO connection number is: " + rawSipo);
        String sipo = rawSipo.replaceFirst("^0+", "");
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setSipoNumber(sipo);

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