package cz.moneta.test.dataprepare.retail;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.tasks.expres.ExpresLoanDataPreparationTasks;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.RepeatedTest;

import java.io.IOException;

@TestScenario(name = "Klienti pro sjednání půjčky")
public class PrepareFopClientForLoansCycle {

    private ExpresLoanDataPreparationTasks loanPrep;

    @BeforeAll
    public void init(Harness harness) {
        loanPrep = new ExpresLoanDataPreparationTasks(harness);
    }

    @RepeatedTest(value = 1, name = "Vytvoření FOP klienty pro sjednání půjčky")
    public void testPrepareClientsForLoans(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) throws IOException {

        NonClient client = loanPrep.createClientData();

        String cif = loanPrep.prepareFopClientForLoans(client);

        Credentials credentials = harness.tasks()
                .wso2()
                .idm()
                .getIbCredentialsByIco(client.ico());

        harness.withIlods().setSegment("AS_FAM", "EXIST", null, client.ico());
        harness.withIlods().setSegment("RSK_INFOLIMIT", "INFOLIMIT_CALC", null, client.ico());
        harness.withIlods().setSegment("CUST_INC_VER", "POI_VALID_STRICTLY", null, client.ico());

        harness.log("Client prepared:");
        harness.log(" - CIF: " + cif);
        harness.log(" - Client ico number: " + client.ico());
        harness.log(" - IB username: " + credentials.getUsername());

        //set your own directory
        //try (FileWriter writer = new FileWriter("C:\\Users\\birthNumbers.txt", true)) {
        //writer.write(client.birthNumber() + "\n");
        //}
    }
}