package cz.moneta.test.regression.cards.jenkinstests;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.ufo.banka.tasks.cards.CardsServicingTasks;
import cz.moneta.test.dsl.util.BankaUtils;
import cz.moneta.test.dsl.util.credentials.Keys;
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.TestScenarioWithOrder;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import cz.moneta.test.regression.commercial.smallbusiness.digital.TearDown;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;

import static cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage.CLIENT_CIF_STORE_KEY;
import static cz.moneta.test.dsl.ufo.banka.pages.main.PSP004_S001_PrintPage.DOCUMENT_URLS_STORE_KEY;
import static cz.moneta.test.harness.annotations.Environment.PPE;

@TestScenarioWithOrder(name = "Teller must be able to Onboard a commercial Cards on same depersonalized cif")
public class ChildCardsOnboarding {

    private NonClient nonClient;
    private BankaTasks bankaTasks;

    @BeforeAll
    protected void setUp(Harness harness) {
        bankaTasks = harness.tasks().ufo().banka();
        nonClient = CardsServicingTasks.setUpChild(harness, harness.getConfig("cards_team.child.onboarding.birth.number"));
    }

    @TestCase(name = "Create New Child Client With Cards", environments = {PPE})
    @JiraTestCase(id = "CT-T5418")
    @Order(1)
    public void setUpFopCifForCardOnboarding(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByNewRc(nonClient.birthNumber()))
                .then(bankaTasks.cardsServicing().createNewChildCif(nonClient, harness.getConfig("cards_team.child.onboarding.firstname"), harness.getConfig("cards_team.child.onboarding.lastname"), harness.getConfig("cards_team.child.onboarding.parent.birth.number"), harness.getConfig("cards_team.child.onboarding.birth.date")))
                .then(bankaTasks.cardsOnboarding().createTomJuniorAccountForNewChildCif());
    }

    @AfterEach
    public void tearDown(Harness harness) {
        harness.store("reports.tmfj.execution.comment",
                "\nIČO klienta: " + nonClient.birthNumber() +
                        "\nCIF klienta: " + harness.get(CLIENT_CIF_STORE_KEY, true) +
                        "\nUFO Session ID: " + harness.get("reports.tmfj.execution.commentufosessionid") +
                        "\nURL dokumentov: \n" + BankaUtils.formatDocumentUrls(harness.get(DOCUMENT_URLS_STORE_KEY, true)));
    }

    @AfterAll
    public void finalTearDown(Harness harness) {
        TearDown.depersonalizeFonClient(harness, nonClient.birthNumber(), harness.get(CLIENT_CIF_STORE_KEY, true));
    }
}
