package cz.moneta.dataprepare;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import cz.moneta.test.regression.commercial.smallbusiness.digital.TearDown;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

public class CustomerDataPrepare {

    private static final Logger logger = LogManager.getLogger(CustomerDataPrepare.class);

    protected Credentials credentials;
    protected String newCustomerCif;
    protected NonClient nonClient;

    /**
     * This method create client before each executed test (if use this as a parent class). Client is created via MWFs.
     * <p>
     * If you want to use custom cif its necessary to define it in config file. Identifier for config: "cif".
     * </p>
     * <p>
     * For more info see: {@link cz.moneta.test.dsl.util.task.dataprepare.DataPrepareTasks}
     * </p>
     *
     * @param harness - Harness store accessor
     * @param banker  - UFO Banka banker credentials
     */
    @BeforeEach
    public void createClient(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        credentials = banker;

        if ((newCustomerCif = harness.getConfig("cif")) != null) {
            logger.info("The cif found in the configuration is used: " + newCustomerCif);
            return;
        }

        nonClient = harness.data().newNonClient()
                .withMobileNumber("725559544");

        newCustomerCif = harness.dataPrepare()
                .createNewFoCustomerViaWso2AndGetCif(nonClient, banker.getUsername());
    }

    @AfterEach
    protected void tearDown(Harness harness) {
        TearDown.storeIcoFullNameCifSessionId(harness);
    }
}