package cz.moneta.test.regression.commercial.smallbusiness.digital.localtests.banka.products.smeautomats.fop;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.newib.tasks.NewIbTasks;
import cz.moneta.test.dsl.ufo.banka.pages.requests.BAL006_S002_ClientRequestPage;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.ufo.banka.tasks.products.NewSmeAutomatFopTasks;
import cz.moneta.test.dsl.ufo.banka.tasks.products.NewSmeAutomatSubTasks;
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.TestScenario;
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 static cz.moneta.test.dsl.ufo.banka.pages.cards.credit.OPN008_S001_SignContractPage.APPLICATION_ID_KEY;
import static cz.moneta.test.dsl.ufo.banka.pages.po.HPO018_S001_AdcPage.INTERNET_BANKING_ID_KEY;
import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenario(name = "Draw Down Fee Express With Sign NIB")
public class DrawDownFeeExpressBusinessWithSignNIB {

    private NonClient nonClient;
    private BankaTasks bankaTasks;
    private NewSmeAutomatFopTasks newSmeAutomatFopTasks;
    private NewSmeAutomatSubTasks newSmeAutomatSubTasks;
    private NewIbTasks newIbTasks;
    String DEFAULT_PASSWORD = "Aa123456";

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

    @TestCase(name = "Draw Down Fee Expres Business With Sign NIB", environments = {TST1, PPE})
    @JiraTestCase(id = "SBD-T1019")
    public void drawDownFeeExpressBusinessWithSignNIB(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        BAL006_S002_ClientRequestPage first_instance = harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByIco(nonClient.ico()))
                .then(bankaTasks.sharedTasks().storeFullNameAndIco())
                .then(bankaTasks.sharedTasks().storeInternetBankingID())
                .then(newSmeAutomatFopTasks.drawDownFeeWithSignNIBExpresBusiness(harness));

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(harness.get(INTERNET_BANKING_ID_KEY), DEFAULT_PASSWORD))
                .then(newIbTasks.checkAndSignNewDocument());

        first_instance
                .clickRequest(harness.get(APPLICATION_ID_KEY))
                .clickOpenRequestDetail()
                .onSMEAutomatsApplicationsOverview()
                .storeAccountNumber("Expres Business");

        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByIco(nonClient.ico()))
                .then(newSmeAutomatSubTasks.checkEstablishedExpresBusinessAccountDetail(harness));

    }

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