package cz.moneta.test.regression.investments;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.newib.investments.InvestmentsTasks;
import cz.moneta.test.dsl.newib.tasks.NewIbTasks;
import cz.moneta.test.dsl.util.data.client.NewClientWithCurrentAccountInformation;
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.BeforeAll;
import org.junit.jupiter.api.Order;

@TestScenarioWithOrder()
public class InvestmentsPurchaseTests {
    NewClientWithCurrentAccountInformation newClient;

   @BeforeAll
   public void createClientForBuying(Harness harness) {
       InvestmentsTasks investTasks = harness.tasks().investmentsTasks();
       newClient = investTasks.prepareClientViaWSO();
       investTasks.logClientInfo(newClient);
   }

    @Order(1)
    @TestCase(name = "Establishment Of An Investment in IB")
    @JiraTestCase(id = "INVEST-T587", project = "Investments")
    public void investment_01_EstablishmentOfAnInvestmentInIB(Harness harness) {
        InvestmentsTasks tasks = harness.tasks().investmentsTasks();
        NewIbTasks ib = harness.tasks().newIb();
        harness.withNewIb().openLoginPage()
                .then(ib.loginWithUsernamePasswordAndDefaultMobKey(newClient.getCredentials().getUsername(), newClient.getCredentials().getPassword()))
                .then(tasks.establishFirstInvestmentE2E());
    }

    @Order(2)
    @TestCase(name = "Purchase fund from each risk profile in IB")
    @JiraTestCase(id = "INVEST-T590", project = "Investments")
    public void investment_02_PurchaseFundFromEachRiskProfile(Harness harness) {
        InvestmentsTasks tasks = harness.tasks().investmentsTasks();
        NewIbTasks ib = harness.tasks().newIb();
        harness.withNewIb().openLoginPage()
                .then(ib.loginWithUsernamePasswordAndDefaultMobKey(newClient.getCredentials().getUsername(), newClient.getCredentials().getPassword()))
                .goToInvestments()
                .clickInvestmentsCard()
                .confirmDisclaimer()
                .waitForMenu()
                .uncoverEntireFundList()
                .then(tasks.purchasedInvestmentFromEachRiskProfile(tasks.getRiskProfileNumbers(), "111111", "11111"));
    }
}