package cz.moneta.test.sanity.transactional.cards.wso2;

import cz.moneta.test.dsl.Harness;
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.TestScenario;
import cz.moneta.test.sanity.transactional.SmokeData;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.BeforeAll;

import java.util.Collections;
import java.util.Random;

@TestScenario(name = "CHG_CARD_BUSINESS_NAME")
public class CardChange {
    private String card;
    private String account;
    private String cif;
    private String adresat;
    private String co;
    private String cp;
    private String obec;
    private String psc;
    private String posta;
    private String ulice;
    private String zeme;
    private SmokeData smokeData;

    @BeforeAll
    public void setUp(Harness harness) {
        smokeData = SmokeData.getInstance(harness);
        account = smokeData.getCreditData().getAccount();
        card = smokeData.getCreditData().getCard();
        cif = smokeData.getCreditData().getCif();
        Random random = new Random();
        adresat = RandomStringUtils.randomAlphabetic(10);
        co = String.valueOf(random.nextInt(10_000));
        cp = String.valueOf(random.nextInt(10_000));
        obec = "Praha";
        posta = "Zimohrad 10";
        ulice = "HOLEJ";
        psc = "14000";
        zeme = "52";
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1941")
    public void MWF8B1_CHG_CARD_BUSINESS_NAME(Harness harness) {
        String name = RandomStringUtils.randomAlphabetic(12);
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWF8B1"))
                .addField("CisloKaretnihoUctu", account)
                .addField("VytlaceneJmeno", name)
                .postExtended()
                .andAssertStatus(200);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1940")
    public void MWF7G2_CHG_CARD_EMBOS_NAME(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWF7G2"))
                .addField("CIF", cif)
                .postExtended()
                .andAssertStatus(200)
                .andAssertPresent("PocetZmenenychKaret");
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1976")
    public void MWFK28_CHG_CARD_STMT_DISTRIBUTION(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFK28"))
                .addField("CisloKaretnihoUctu", account)
                .addField("CisloKarty", "")
                .addField("ZpusobDistribuceVypisu", "1")
                .postExtended()
                .andAssertStatus(200);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1930")
    public void MWF140_SET_CARD_CHANGE_PIN_ADDRESS(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWF140"))
                .addField("Adresat", adresat)
                .addField("CO", co)
                .addField("CP", cp)
                .addField("Obec", obec)
                .addField("PSC", psc)
                .addField("Pocet", 1)
                .addField("PolePoradi", account)
                .addField("Ulice", ulice)
                .addField("Zeme", zeme)
                .addField("Posta", posta)
                .addField("inputset", Collections.emptyList())
                .appendToArray("inputset", new Object())
                .addField("inputset[0]", "CisloProduktu", card)
                .addField("inputset[0]", "Adresat", adresat)
                .postExtended()
                .andAssertStatus(200);
    }
}
