package cz.moneta.test.regression.commercial.smallbusiness.digital.localtests.banka.testscenarios;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.main.codelists.HCisProductClass;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.harness.annotations.EnableIfSet;
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.DataPrepare;
import cz.moneta.test.regression.commercial.smallbusiness.digital.TearDown;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;

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

@TestScenarioWithOrder(name = "Saving Account FOP")
public class CreateFopSavingAccount {

    private NonClient nonClient;
    private BankaTasks bankaTasks;

    @BeforeAll
    protected void setUp(Harness harness) {
        bankaTasks = harness.tasks().ufo().banka();
        nonClient = DataPrepare.setUpFop(harness);
    }

    @TestCase(name = "Create New FOP Client", environments = {TST1, PPE})
    @Order(1)
    @JiraTestCase(id = "SBD-T480")
    public void createNewFopCif(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByNewIco(nonClient.ico()))
                .then(bankaTasks.newFopClient().createFopCif(nonClient))
                .then(bankaTasks.sharedTasks().storeFullNameAndIco())
                .verifyThatCifIsValid();

        harness.storeGlobal("FOP_CIF_CREATED", "PASS");
    }

    @EnableIfSet(globalKey = "FOP_CIF_CREATED")
    @TestCase(name = "Create Current Account with Internet Banking", environments = {TST1, PPE})
    @Order(2)
    @JiraTestCase(id = "SBD-T402")
    public void createCurrentAccountForFop(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByIco(nonClient.ico()))
                .then(bankaTasks.newCurrentAccountTasks().createCurrentAccountFop(harness, nonClient))
                .then(bankaTasks.sharedTasks().storeFullNameAndIco())
                .verifyThatClientHasSomeActiveProducts();

        harness.storeGlobal("CURR_ACC_PASSED", "PASS");
    }

    @EnableIfSet(globalKey = "CURR_ACC_PASSED")
    @TestCase(name = "Saving Account", environments = {TST1, PPE})
    @Order(3)
    @JiraTestCase(id = "SBD-T456")
    public void createSavingAccountFop(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByIco(nonClient.ico()))
                .then(bankaTasks.newProduct().createNewSavingsAccount("Spořící účet"))
                .then(bankaTasks.sharedTasks().storeFullNameAndIco());
    }

    @AfterEach
    public void tearDown(Harness harness) {
        TearDown.storeIcoFullNameCifSessionId(harness);
    }
}