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.FileWriter;
import java.io.IOException;

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

    private ExpresLoanDataPreparationTasks loanPrep;

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

    @RepeatedTest(value = 10, name = "Vytvoření FO 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.prepareClientForLoans(client);

        Credentials credentials = harness.tasks()
                .wso2()
                .idm()
                .getIbCredentialsByRC(client.birthNumber());

        String clientId = harness.withUdebs()
                .usersTable()
                .getClientId(client.birthNumber());

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

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