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

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.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeAll;

@TestScenario(name = "CARD DETAILS")
public class CardDetails {
    private String card;
    private String account;
    private String contract;
    private String rc;
    private String name;
    private String bu;
    private SmokeData smokeData;

    @BeforeAll
    public void getInfo(Harness harness) {
        smokeData = SmokeData.getInstance(harness);
        CardData creditData = smokeData.getCreditData();
        card = creditData.getCard();
        account = creditData.getAccount();
        contract = creditData.getContract();
        rc = creditData.getRc();
        name = creditData.getName();
        bu = creditData.getBu();
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1969")
    public void MWFIY1GetAccountCardDetail(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFIY1"))
                .addField("CisloKarty", card)
                .addField("CisloKaretnihoUctu", account)
                .postExtended()
                .andAssertStatus(200)
                .andAssertPresent("CisloInstantniKarty")
                .andAssertFieldValue("CisloKaretnihoUctu", account)
                .andAssertFieldValue("CisloSmlouvy", contract);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T2420")
    public void MWF35DCardDetailGetCardOwner(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromNas(smokeData.getPath("MWF35D"))
                .addField("CARD_NUMBER", card)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("CONTRACT_NUMBER", contract)
                .andAssertFieldValue("PERSONAL_ID_CARD_OWNER", rc);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1934")
    public void MWF423GetCardListDetailForPrint(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWF423"))
                .addField("CisloKaretnihoUctu", account)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("Data[0].CisloSmlouvy", contract)
                .andAssertFieldValue("Data[0].JmenoMajitel", name.toUpperCase());
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1967")
    public void MWFIX1GetCardAccountDispositions(Harness harness) {
        //only credit card
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFIX1"))
                .addField("CisloKarty", card)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("CisloKaretnihoUctu", account)
                .andAssertFieldValue("CisloSmlouvy", contract);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1968")
    public void MWFIY0GetAccountBasicCardDetail(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFIY0"))
                .addField("CisloKaretnihoUctu", account)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("CisloKaretnihoUctu", account)
                .andAssertFieldValue("MajitelJmeno", name.toUpperCase())
                .andAssertFieldValue("CisloSmlouvy", contract);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1948")
    public void MWFB05ChkCardType(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFB05"))
                .addField("CisloKarty", card)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("DruhKarty", "1")
                .andAssertFieldValue("KartaExistuje", "1");
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1950")
    public void MWFB63GetCardDetailSme(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFB63"))
                .addField("CisloKaretnihoUctu", account)
                .postExtended()
                .andAssertStatus(200)
                .andAssertPresent("APodPSC");
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1964")
    public void MWFI80GetAccountDetail(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromWps(smokeData.getPath("MWFI80"))
                .addField("CONTRACT_NUMBER", account)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("REL_NUMBER", "000861000" + contract);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T2434")
    public void MWFL55GetAutoCancelInterestList(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFL55"))
                .addField("CisloKarty", card)
                .postExtended()
                .andAssertStatus(200)
                .andAssertPresent("Data")
                .andAssertFieldValue("Data[0].UrokyCelkem", "0");
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1979")
    public void MWFL56GetAutoCancelDetail(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFL56"))
                .addField("CisloKarty", card)
                .postExtended()
                .andAssertStatus(200)
                .andAssertPresent("BlokacniKod")
                .andAssertPresent("DatumZacatkuZruseni");
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1965")
    public void MWFIR1GetCardListAllForIb(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareRequestFromCbl(smokeData.getPath("MWFIR1"), "{\"RWS_VstupniKarty\":[{}]}")
                .addField("RWS_VstupniKarty[0]", "CARD_NBR", card)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("RWS_DetailyKaret[0].CisloKaretnihoUctu", account)
                .andAssertFieldValue("RWS_DetailyKaret[0].CisloSmlouvy", contract);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T2438")
    public void MWFXXX4AccountGetDetail(Harness harness) {
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFXXX4"))
                .addField("ACCOUNT", account)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("ACCT_ACCT_NBR", account)
                .andAssertFieldValue("ACCT_SHORT_NAME", name.toUpperCase())
                .andAssertFieldValue("ACCT_BANK_ACCT_NBR", StringUtils.repeat('0', 8) + bu);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1973")
    public void MWFJP3DoCardServMaskCardNumber(Harness harness) {
        String expectedMask = account.substring(0, 4)
                + StringUtils.repeat('*', 11)
                + account.substring(15);
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromHub(smokeData.getPath("MWFJP3"))
                .addField("CisloKaretnihoUctu", account)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("CisloKaretnihoUctuMask", expectedMask);
    }
}
