package cz.moneta.test.regression.cvm.api.digitalchannelssb;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.support.rest.RawRestRequest;
import org.junit.jupiter.api.Assertions;

import java.time.ZonedDateTime;
import java.util.List;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenario(name = "Call API get-card-authorizations to WSO2 and assert response parameters")
public class ApiGetCardAuthorizations {

    @TestCase(name = "Call API get-card-authorizations to WSO2", environments = {TST1, PPE})
    public void postGetCardAuthorizations(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromCvm(
                "digitalchannels.sb/get-card-authorizations/001", false,
                "{\n" +
                        "  \"amountTo\": 100000,\n" +
                        "  \"amountFrom\": 100,\n" +
                        "  \"currency\": \"CZK\",\n" +
                        "  \"dateFrom\": \"" + ZonedDateTime.now().withNano(0).minusDays(1).withFixedOffsetZone() + "\",\n" +
                        "  \"cardNumber\": \"5351233153047817\"\n" +
                        "}")
                .postExtended()
                .andAssertPresent("authorizations")
                .andAssertPresent("count")
                .andAssertStatus(200);

        List<Object> activityIds = response.getHeader("activityId");
        Assertions.assertEquals(1, activityIds.size(), "API should return activityId header");
    }
}