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.main.HKO101_S001_MainClientPage;
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.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.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 = "Create Expres Business with NIB for FOP")
public class CreateExpresBusinessWithSignNIB {

    private NonClient nonClient;
    private BankaTasks bankaTasks;
    private NewIbTasks newIbTasks;
    String DEFAULT_PASSWORD = "Aa123456";

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

    @TestCase(name = "Create Expres Business With Sign NIB", environments = {TST1, PPE})
    @JiraTestCase(id = "SBD-T986")
    public void createExpresBusinessWithSignNIB(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        String dummyEmail = "dummy.a1a2a3a4a5a6a7a8@ge.com";
        String loanExpresAmount = "500000";
        String lastYear = DataPrepare.getLastYear();
        String yearBeforeLast = DataPrepare.getYearBeforeLast();

        HKO101_S001_MainClientPage first_instance = harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByIco(nonClient.ico()))
                .then(bankaTasks.sharedTasks().storeFullNameAndIco())
                .then(bankaTasks.newSmeAutomatFopTasks().withExpresBusinessSendToNIB(harness, dummyEmail, loanExpresAmount, lastYear, yearBeforeLast))
                .then(bankaTasks.sharedTasks().storeInternetBankingID());

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

        first_instance
                .then(bankaTasks.newSmeAutomatFopTasks().finishExpressApplicationAFterNIBSign(harness, "PODMÍNĚNÝ SOUHLAS"));

    }

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