package cz.moneta.test.regression.commercial.cb.archive;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.cb.landing.SME401_S001_SearchPage;
import cz.moneta.test.dsl.util.data.client.NewClientCommercial;
import cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks;
import cz.moneta.test.harness.annotations.Environment;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;

import static cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks.JIRA_COMMENT_STORE_KEY;

@Disabled
@TestScenario(name = "Test checks searching by ICO")
public class CheckSearchingClient {

    private NewClientCommercial client;
    private CommercialTasks tasks;

    @BeforeAll
    public void setUp(Harness harness) {
        tasks = harness.tasks().ufo().cb();
        client = tasks.createNewGlobalFopBe();
    }

    private SME401_S001_SearchPage accessSearchPage(Harness harness) {
        return harness.withUfo()
                .openLoginPage()
                .then(tasks.loginAsCbBanker())
                .clickSearchLink();
    }

    @TestCase(name = "Check if searching by ICO is working", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T369")
    public void checkSearchByIco(Harness harness) {
        String ico = this.client.getClientData().ico();
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("ICO: %s <br>", ico));
        accessSearchPage(harness)
                .pickIco()
                .typeDetailForSearch(ico)
                .clickSearch()
                .checkIco(ico);
    }

    @TestCase(name = "Check if searching by ICO starting with 0 is working", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T370")
    public void checkSearchByIcoStartingZero(Harness harness) {
        String ico = harness.getConfig("commercial.cb.ico-zero"); //TODO replace witch dynamic data in the future
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("ICO: %s <br>", ico));
        accessSearchPage(harness)
                .pickIco()
                .typeDetailForSearch(ico)
                .clickSearch()
                .checkIco(ico);
    }

    @TestCase(name = "Check if searching by RC is working", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T371")
    public void checkSearchByRc(Harness harness) {
        String rc = harness.getConfig("commercial.cb.rc-fo");
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("RC: %s <br>", rc));
        accessSearchPage(harness)
                .pickRc()
                .typeDetailForSearch(rc)
                .clickSearch()
                .checkRc(rc);
    }

    @TestCase(name = "Check if searching by CIF is working", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T372")
    public void checkSearchByCif(Harness harness) {
        String cif = client.getCif();
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("CIF: %s <br>", cif));
        accessSearchPage(harness)
                .pickCif()
                .typeDetailForSearch(cif)
                .clickSearch()
                .clickDetailedClientInfo()
                .checkCif(cif);
    }

    @TestCase(name = "Check if searching by proposalID is working", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T373")
    public void checkSearchByProposalId(Harness harness) {
        String proposalId = harness.getConfig("commercial.cb.proposal-id"); //TODO replace witch dynamic data in the future
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("Proposal ID: %s <br>", proposalId));
        accessSearchPage(harness)
                .pickProposalId()
                .typeDetailForSearch(proposalId)
                .clickSearch()
                .checkProposalId(proposalId);
    }

    @TestCase(name = "Check if searching by ACCOUNT NUMBER is working", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T381")
    public void checkSearchByAccountNumber(Harness harness) {
        String accNum = harness.getConfig("commercial.cb.account-number"); //TODO replace witch dynamic data in the future
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("Account number: %s <br>", accNum));
        accessSearchPage(harness)
                .pickAccountNumber()
                .typeDetailForSearch(accNum)
                .clickSearch()
                .checkAccNum(accNum);
    }

    @TestCase(name = "Check if searching by ACCOUNT NUMBER starting with 0 is working", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T875")
    public void checkSearchByAccountNumberStartingZero(Harness harness) {
        String accNum = harness.getConfig("commercial.cb.account-number-zero");
        String regex = "^0+(?!$)";
        String accNumWithoutZeros = accNum.replaceAll(regex, "");
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("Account number: %s <br>", accNum));
        accessSearchPage(harness)
                .pickAccountNumber()
                .typeDetailForSearch(accNum)
                .clickSearch()
                .checkAccNum(accNumWithoutZeros);
    }

    @TestCase(name = "Check if searching by CLIENT ID is working", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T374")
    public void checkSearchByClientId(Harness harness) {
        String personId = this.client.getPersonId().toString();
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("Person ID: %s <br>", personId));
        accessSearchPage(harness)
                .pickClientId()
                .typeDetailForSearch(personId)
                .clickSearch()
                .clickDetailedClientInfo()
                .checkClientId(personId);
    }

    @TestCase(name = "Check if searching by REG NUMBER is working", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T375")
    public void checkSearchByRegNum(Harness harness) {
        String regNum = harness.getConfig("commercial.cb.reg-number"); //TODO replace witch dynamic data in the future
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("Registration number: %s <br>", regNum));
        accessSearchPage(harness)
                .pickRegNum()
                .typeDetailForSearch(regNum)
                .clickSearch()
                .checkRegNum(regNum);
    }
}