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

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.time.LocalDate;

import static cz.moneta.test.sanity.transactional.cards.firstvision.MESSAGE.FV;
import static cz.moneta.test.sanity.transactional.cards.firstvision.MESSAGE.SVC_RETURN;
import static cz.moneta.test.sanity.transactional.cards.firstvision.MESSAGE.VMX_MSGIN;

@TestScenario(name = "VMX.ACCT.CANCEL.UPD")
public class AccountCancel {
    private String account;

    @BeforeAll
    public void getInfo(Harness harness) {
        account = SmokeData.getInstance(harness).getCreditData().getAccount();
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T3882")
    public void accountCancelUpdate(Harness harness) {
        String cancelDateString = DateUtils.getDateWithFormat(LocalDate.now().plusDays(7),
                DateFormatPatterns.FIRST_VISION_DATE_FORMAT_WITHOUT_SEPARATOR);
        harness.withWso2()
                .prepareRequest()
                .withPath(FV)
                .withPojoPayload(new MESSAGE("VMX.ACCT.CANCEL.UPD", "E8V1"))
                .addField(VMX_MSGIN, "ACCT_NBR", account)
                .addField(VMX_MSGIN, "CNCL_DATE", cancelDateString)
                .postExtended()
                .andAssertStatus(200)
                .andAssertFieldValue(SVC_RETURN, "P");
    }
}
