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

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;

import static cz.moneta.test.sanity.transactional.cards.firstvision.MESSAGE.*;

@TestScenario(name = "Customer update/inquiry")
public class Customer {
    private String account;
    private String name;
    private String bu;

    @BeforeAll
    public void getInfo(Harness harness) {
        SmokeData smokeData = SmokeData.getInstance(harness);
        CardData creditData = smokeData.getCreditData();
        account = creditData.getAccount();
        name = creditData.getName();
        bu = StringUtils.repeat('0', 8) + creditData.getBu();
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1910")
    public void VMX_CUSTOMER_UPD_EMEA_E8V7(Harness harness) {
        harness.withWso2()
                .prepareRequestXml()
                .withPath(FV)
                .withPayloadFromFile("regression/transactional/cards/sme/R2-VMX.CUSTOMER.UPD.EMEA.E8V7.xml")
                .addField(VMX_MSGIN + ".MODULE005-VMXMSGIN.CUST_AFFORD_UPDATE_IN", "ACCT_NBR", account)
                .postExtended()
                .andAssertFieldValue(SVC_RETURN, "P")
                .andAssertFieldValue(VMX_MSGOUT + ".ORG", "861");
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1917")
    public void VMX_CARD_CUST_ACCT_INQ_CINEMA(Harness harness) {
        harness.withWso2()
                .prepareRequest()
                .withPath(FV)
                .withPojoPayload(new MESSAGE("VMX.CARD.CUST.ACCT.INQ.CINEMA", "E8VCE"))
                .addField(VMX_MSGIN, "ACCOUNT", account)
                .postExtended()
                .andAssertFieldValue(SVC_RETURN, "P")
                .andAssertFieldValue(VMX_MSGOUT + ".ACCOUNT_OUTPUT.SHORT_NAME", name.toUpperCase())
                .andAssertFieldValue(VMX_MSGOUT + ".ACCOUNT_OUTPUT.BANK_ACCT", bu);
    }
}
