package cz.moneta.test.regression.channels.branch.archive;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.util.DateUtils;
import cz.moneta.test.dsl.util.TestUtils;
import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.endpoints.testautomationdb.TestAutomationDbEndpoint;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.Disabled;

import static cz.moneta.test.dsl.util.credentials.Keys.ufo;
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;
import static cz.moneta.test.harness.support.data.GeneratorType.RC;

@Disabled("Duplicates SBD - SBD-T480")
@TestScenario(name = "Teller must be able to crate a new FOP customer")
public class CreateNewFopCustomer {

    @TestCase(name = "Bank teller is able to login and create a new FOP customer", environments = {TST1, PPE, EDU})
    @JiraTestCase(id = "POB-T10637")
    public void tc_bank_teller_is_able_create_new_fop_customer(Harness harness, @Key(ufo.banka.banker) Credentials banker) {

        BankaTasks withBanka = harness.tasks().ufo().banka();

        String birthNumber = harness.generate(RC);
        NonClient nonClient = harness.data().newNonClient()
                .withBirthNumber(birthNumber)
                .withEmail(TestUtils.getEmailBasedOnRc(birthNumber));

        HKO101_S001_MainClientPage mainPage = harness.withUfo()
                .openLoginPage()
                .then(withBanka.login().withCredentialsAndTurnOffSignpad(banker))
                .then(withBanka.newFopClient().createFopCif(nonClient))
                .verifyThatCifIsValid();

        String newClientCif = mainPage.getCif();
        String nodeHost = harness.getEndpoint(UfoEndpoint.class).getNodeHost();
        String createdDateTime = DateUtils.getFormattedTodayDateTime("yyyy-MM-dd hh:mm:ss");
        harness.getEndpoint(TestAutomationDbEndpoint.class)
                .insertCreatedClientInfo(newClientCif, nonClient.birthNumber(), nonClient.ico(), createdDateTime, banker.getUsername(), "UFO", nodeHost);
    }

}
