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.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.concurrent.ThreadLocalRandom;

@TestScenario(name = "ACCOUNT_MONETARY_UPD")
public class AccountMonetaryUpd {
    private String account;
    private SmokeData smokeData;
    private int randomAmount;

    @BeforeAll
    public void getInfo(Harness harness) {
        smokeData = SmokeData.getInstance(harness);
        account = smokeData.getCreditData().getAccount();
        randomAmount = ThreadLocalRandom.current().nextInt(100, 300 + 1);
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T2751")
    public void MWFXXX8_ACCOUNT_MONETARY_UPDATE(Harness harness) {
        String todayDate = DateUtils.getFormattedTodayDate(DateFormatPatterns.FIRST_VISION_DATE_FORMAT_WITH_SEPARATOR);
        harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromErn(smokeData.getPath("MWFXXX8"))
                .addField("ACCT_ORG", "500")
                .addField("ACCT_NBR", account)
                .addField("CURR_CODE", "203")//CZK currency
                .addField("FOREIGN_USE", "0")
                .addField("ACTION_CODE", "PCOL")//Fee for reminder mail
                .addField("EFF_DATE", todayDate)
                .addField("TXN_AMOUNT", randomAmount)
                .addField("PLAN_NBR", "10000")
                .addField("MCC", "0")
                .addField("STORE_NBR", "999999998")
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue("CARD_NBR", account)
                .andAssertFieldValue("TXN_AMOUNT", Double.toString(randomAmount / 100.));
    }
}
