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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.wso2.Wso2Utils;
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.harness.support.rest.RawRestRequest;
import cz.moneta.test.sanity.transactional.SmokeData;
import org.junit.jupiter.api.BeforeAll;

import java.util.Random;

@TestScenario(name = "card-servicing/generate-pin")
public class GeneratePin {
    private SmokeData smokeData;
    private String card;
    private String mobile;

    @BeforeAll
    public void getInfo(Harness harness) {
        smokeData = SmokeData.getInstance(harness);
        card = smokeData.getCreditData().getCard();
        mobile = (100_000_000 + new Random().nextInt(899_999_999)) + "";
    }

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T2424")
    public void MWFA85_CARD_SERVICING_GENERATE_PIN(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest()
                .prepareEmptyRequestFromUfo(smokeData.getPath("MWFA85"))
                .addField("CisloKarty", card)
                .addField("ZpusobDistribucePIN", "1")
                .addField("SmartPINNumber", mobile)
                .postExtended();

        //fixme this test can be run only once during batch period, else got 500
        Wso2Utils.validateResponse(response,
                500,
                smokeData.isGw(),
                "tifResponseStatus.errorDesc",
                "VPL5SPR29S: CARD ACTION CHANGE NOT ALLOWED DUE TO PENDING CARD ACTION",
                "errorMessage",
                "CARD ACTION CHANGE NOT ALLOWED DUE TO PENDING CARD ACTION");
    }
}
