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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.salesforce.data.EventData;
import cz.moneta.test.dsl.salesforce.data.OpportunityData;
import cz.moneta.test.dsl.salesforce.data.SaleData;
import cz.moneta.test.dsl.ufo.cb.landing.KOM401_S001_ProposalParameters;
import cz.moneta.test.dsl.ufo.cb.landing.proposals.EuInvestment;
import cz.moneta.test.dsl.util.data.client.NewClientCommercial;
import cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks;
import cz.moneta.test.dsl.util.task.ufo.cb.ProposalTasks;
import cz.moneta.test.dsl.util.task.wso2.ClientTasks;
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.AfterAll;
import org.junit.jupiter.api.Assertions;
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 workflow of product")
public class CheckEuInvestmentWorkFlow {

    private EuInvestment proposal;
    private CommercialTasks commercialTasks;
    private ProposalTasks proposalTasks;
    private String ico;

    @BeforeAll
    public void setUp(Harness harness) {
        commercialTasks = harness.tasks().ufo().cb();
        proposalTasks = commercialTasks.proposalTasks();
        NewClientCommercial newClientCommercial = commercialTasks.createNewFop();
        commercialTasks.linkNewFopClientToSalesForce(newClientCommercial);
        ico = newClientCommercial.getClientData().ico();
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("ICO: %s <br>", ico));
        Assertions.assertNotEquals(-1, newClientCommercial.getPersonId().intValue(), "Client was not saved in Comoda.");
        OpportunityData opportunityData = OpportunityData.builder().build().getInvestmentOpportunity();
        opportunityData.setAccount(ico);
        EventData eventData = EventData.builder().build().getMeetingActiveBusiness();
        SaleData saleData = SaleData.builder().build().getInvestmentSale();
        harness.withSalesForce()
                .openLoginPage()
                .then(harness.tasks().salesForce().loginAsBanker())
                .then(harness.tasks().salesForce().newOpportunityTasks().newOpportunity(opportunityData, eventData, saleData));
        proposal = new EuInvestment();
        ClientTasks clientTasks = harness.tasks().wso2().client();
        harness.withUfo()
                .openLoginPage()
                .then(commercialTasks.loginAsCbBanker())
                .then(commercialTasks.searchClient(ico))
                .then(proposalTasks.createProposal())
                .then(proposalTasks.fillProposalEuInvestment(proposal))
                .then(proposalTasks.saveProposal(proposal));
        commercialTasks.appendJiraComment(String.format("Proposal ID: %s", proposal.getProposalId()));
        clientTasks.calculateTotalExposurePerson(newClientCommercial.getPersonId());
    }

    @AfterAll
    public void destroy(Harness harness) {
        Assertions.assertNotEquals(null, proposal.getProposalId(), "Proposal was not created, that means it can not be deleted.");
        harness.withUfo()
                .openLoginPage()
                .then(commercialTasks.loginAsCbBanker())
                .then(proposalTasks.deleteProposal(proposal.getProposalId()));
    }

    private KOM401_S001_ProposalParameters accessProposal(Harness harness) {
        return harness.withUfo()
                .openLoginPage()
                .then(commercialTasks.loginAsCbBanker())
                .then(proposalTasks.proposalSignpost(proposal.getProposalId()));
    }

    @TestCase(name = "Check relations screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T444")
    public void checkRelationsScreen(Harness harness) {
        accessProposal(harness).clickRelations();
    }

    @TestCase(name = "Check client card screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T445")
    public void checkClientCardScreen(Harness harness) {
        accessProposal(harness).clickClient();
    }

    @TestCase(name = "Check fv screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T446")
    public void checkFvScreen(Harness harness) {
        accessProposal(harness).clickFv();
    }

    @TestCase(name = "Check rating screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T447")
    public void checkRatingScreen(Harness harness) {
        accessProposal(harness).clickRating();
    }

    @TestCase(name = "Check cru screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T449")
    public void checkCruScreen(Harness harness) {
        accessProposal(harness).clickCru();
    }

    @TestCase(name = "Check modelation screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T450")
    public void checkModelationScreen(Harness harness) {
        accessProposal(harness).clickModelation();
    }

    @TestCase(name = "Check pledge bonds screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T451")
    public void checkPledgeBondsScreen(Harness harness) {
        accessProposal(harness).clickPledgeBonds();
    }

    @TestCase(name = "Check black lists screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T452")
    public void checkBlackListsScreen(Harness harness) {
        accessProposal(harness).clickBlackLists();
    }

    @TestCase(name = "Check pricing screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T453")
    public void checkPricingScreen(Harness harness) {
        accessProposal(harness).clickPricing();
    }

    @TestCase(name = "Check nrki brki screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T454")
    public void checkNrkiBrkiScreen(Harness harness) {
        accessProposal(harness).clickNrkiBrki();
    }

    @TestCase(name = "Check description screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T455")
    public void checkDescriptionScreen(Harness harness) {
        accessProposal(harness).clickDescription();
    }

    @TestCase(name = "Check basic information screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T456")
    public void checkBasicInformationScreen(Harness harness) {
        accessProposal(harness).clickBasicInformation();
    }

    @TestCase(name = "Check resources moneta screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T457")
    public void checkResourcesMonetaScreen(Harness harness) {
        accessProposal(harness).clickResourcesMoneta();
    }

    @TestCase(name = "Check resources screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T458")
    public void checkResourcesScreen(Harness harness) {
        accessProposal(harness).clickResources();
    }

    @TestCase(name = "Check sales employee screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T459")
    public void checkSalesEmployeeScreen(Harness harness) {
        accessProposal(harness).clickSalesEmployee();
    }

    @TestCase(name = "Check risk screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T460")
    public void checkRiskScreen(Harness harness) {
        accessProposal(harness).clickRisk();
    }

    @TestCase(name = "Check client accounts screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T461")
    public void checkClientAccountsScreen(Harness harness) {
        accessProposal(harness).clickClientAccounts();
    }

    @TestCase(name = "Check covenants in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T462")
    public void checkCovenantScreen(Harness harness) {
        accessProposal(harness).clickCovenants();
    }

    @TestCase(name = "Check conditions fulfilment screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T463")
    public void checkConditionsFulfilmentScreen(Harness harness) {
        accessProposal(harness).clickConditionsFulfilment();
    }

    @TestCase(name = "Check deal conditions in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T464")
    public void checkDealConditionsScreen(Harness harness) {
        accessProposal(harness).clickDealConditions();
    }

    @TestCase(name = "Check checklists screen in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T465")
    public void checkChecklistsScreen(Harness harness) {
        accessProposal(harness).clickChecklists();
    }

    @TestCase(name = "Check send proposal in proposal.", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T466")
    public void checkSendProposalScreen(Harness harness) {
        accessProposal(harness).clickSendProposal();
    }
}