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.proposals.EuWorkingCapital;
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.harness.annotations.Environment;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenarioWithOrder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Order;

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

@Disabled
@TestScenarioWithOrder(name = "Test checks creation of proposal and delete of proposal")
public class CheckEuWcCreateDelete {
    private EuWorkingCapital proposal;
    private String ico;
    private CommercialTasks tasks;
    private ProposalTasks proposalTasks;

    @BeforeAll
    public void setUp(Harness harness) {
        tasks = harness.tasks().ufo().cb();
        proposalTasks = tasks.proposalTasks();
        NewClientCommercial newClientCommercial = tasks.createNewFop();
        tasks.linkNewFopClientToSalesForce(newClientCommercial);
        ico = newClientCommercial.getClientData().ico();
        harness.store(JIRA_COMMENT_STORE_KEY, String.format("ICO: %s <br>", ico));
    }

    @Order(value = 1)
    @TestCase(name = "Test creates proposal in SalesForce", environments = {Environment.TST1, Environment.PPE})
    public void createProposalInSalesforce(Harness harness) {
        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));
    }

    @Order(value = 2)
    @TestCase(name = "Test creates proposal - EU Provoz", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T397")
    public void createProposal(Harness harness) {
        proposal = new EuWorkingCapital();
        harness.withUfo()
                .openLoginPage()
                .then(tasks.loginAsCbBanker())
                .then(tasks.searchClient(ico))
                .then(proposalTasks.createProposal())
                .then(proposalTasks.fillProposalEuWc(proposal))
                .then(proposalTasks.saveProposal(proposal));
        tasks.appendJiraComment(String.format("Proposal ID: %s", proposal.getProposalId()));
    }

    @Order(value = 3)
    @TestCase(name = "Test deletes proposal - EU Provoz", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T408")
    public void deleteProposal(Harness harness) {
        Assertions.assertNotEquals(null, proposal.getProposalId(), "Proposal was not created, that means it can not be deleted.");
        harness.withUfo()
                .openLoginPage()
                .then(tasks.loginAsCbBanker())
                .then(proposalTasks.deleteProposal(proposal.getProposalId()));
    }
}
