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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.util.DateFormatPatterns;
import cz.moneta.test.dsl.util.DateUtils;
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 cz.moneta.test.sanity.transactional.cards.firstvision.Payments;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.BeforeAll;

@TestScenario(name = "REPAYMENT TRANSACTION")
public class RepaymentTransactions {
    private String account;
    private String contract;
    private String date;
    private SmokeData smokeData;

    @BeforeAll
    public void getInfo(Harness harness) {
        smokeData = SmokeData.getInstance(harness);
        CardData creditData = smokeData.getCreditData();
        account = creditData.getAccount();
        contract = creditData.getContract();
        date = DateUtils.getFormattedTodayDate(DateFormatPatterns.FIRST_VISION_DATE_FORMAT_WITH_SEPARATOR);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T2421")
    public void MWF420_SET_REPAYMENT_TRANSACTION(Harness harness) {
        String paycoreId = Payments.getFpsId().substring(6);
        String description = "smoke" + RandomStringUtils.randomAlphabetic(25);
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromPay(smokeData.getPath("MWF420"))
                .addField("CONSTANT_SYMBOL", 0)
                .addField("CONTRACT_NBR", contract)
                .addField("CONTRACT_ORG", "500")
                .addField("CURR_CODE", 203)
                .addField("CUST_BANK_ACCT", account)
                .addField("CUST_BANK_CODE", "0600")
                .addField("DATE_OF_PAYMENT", date)
                .addField("DESCRIPTION", description)
                .addField("PAYCORE_ID", paycoreId)
                .addField("TRAN_UNIQUE_ID", "V00" + paycoreId)
                .addField("SPECIFIC_SYMBOL", 0)
                .addField("TXN_AMOUNT", 665)
                .addField("TXN_TYPE", "PYMT")
                .addField("TYPE_OF_PAYMENT", 10)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("PAYCORE_ID", paycoreId)
                .andAssertFieldValue("TRAN_UNIQUE_ID", "V00" + paycoreId);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T2422")
    public void MWF420plus_SET_NEG_REPAYMENT_TRANSACTION(Harness harness) {
        String paycoreId = Payments.getFpsId().substring(6);
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromPay(smokeData.getPath("MWF420+"))
                .addField("PAYCORE_ID", paycoreId)
                .addField("CUST_BANK_ACCT", account)
                .addField("TXN_AMOUNT", 333)
                .addField("DATE_OF_PAYMENT", date)
                .addField("TXN_TYPE", "PYRV")
                .addField("CUST_BANK_CODE", "0600")
                .addField("CONSTANT_SYMBOL", 0)
                .addField("CONTRACT_NBR", contract)
                .addField("CONTRACT_ORG", "500")
                .addField("CURR_CODE", 203)
                .addField("DESCRIPTION", "some negative description")
                .addField("TRAN_UNIQUE_ID", "V00" + paycoreId)
                .addField("SPECIFIC_SYMBOL", 0)
                .addField("TYPE_OF_PAYMENT", 10)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("PAYCORE_ID", paycoreId)
                .andAssertFieldValue("TRAN_UNIQUE_ID", "V00" + paycoreId);
    }
}
