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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.wso2.data.CardData;
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.junit.jupiter.api.BeforeAll;

import java.util.Collections;

@TestScenario(name = "CardPctTable")
public class CardPctTable {
    private String card;
    private String cardDebit;
    private String account;
    private String accountDebit;
    private SmokeData smokeData;

    @BeforeAll
    public void getInfo(Harness harness) {
        smokeData = SmokeData.getInstance(harness);
        CardData creditData = smokeData.getCreditData();
        card = creditData.getCard();
        account = creditData.getAccount();
        CardData debitData = smokeData.getDebitData();
        accountDebit = debitData.getAccount();
        cardDebit = debitData.getCard();
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1931")
    public void MWF1G4_SET_PCT_TABLE(Harness harness) {
        String newPct = "T04".equalsIgnoreCase(GET_PCT_TABLE(harness, card)) ? "W04" : "T04";
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWF1G4"))
                .addField("CardAccountNumber", account)
                .addField("PctId", newPct)
                .postExtended()
                .andAssertStatus(200);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T2783")
    public void MWFXX12_card_change_supp_fee(Harness harness) {
        String newPct = GET_PCT_TABLE(harness, cardDebit).equalsIgnoreCase("GI0") ? "GO0" : "GI0";
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFXX12"))
                .addField("CisloKaretnihoUctu", accountDebit)
                .addField("PCTTabulka", newPct)
                .addField("Data", Collections.emptyList())
                .appendToArray("Data", cardDebit)
                .postExtended()
                .andAssertStatus(200);
    }

    private String GET_PCT_TABLE(Harness harness, String card) {
        return harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFJY9"))
                .addField("CisloKarty", card)
                .postExtended()
                .andAssertStatus(200)
                .andAssertPresent("PCTTabulkaNaKarte")
                .extract("PCTTabulkaNaKarte").textValue();
    }
}
