package cz.moneta.test.dsl.util.task.mvcr;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.endpoints.mvcr.MvcrEndpoint;
import org.apache.commons.lang3.StringUtils;

import java.util.Collections;
import java.util.HashMap;

@SuppressWarnings("all")
public class MvcrTasks {

    private final Harness harness;

    public MvcrTasks(Harness harness) {
        this.harness = harness;
    }

    public boolean checkIdCardValidity(String cardNumber) {
        HashMap<String, Object> params = new HashMap<String, Object>() {{
            put("dotaz", cardNumber);
            put("doklad", "0");
        }};

        String response = harness.getEndpoint(MvcrEndpoint.class)
                .get("/neplatne-doklady/doklady.aspx", params, String.class, Collections.emptyMap())
                .getRight();

        return !StringUtils.contains(response, "evidovano=\"ano\"");
    }

    /**
     * Workaround because direct connection to MVČR has stopped working at 21.10.2024
     * @param cardNumber
     * @return
     */
    public boolean checkIdCardValidityWso2(String cardNumber) {
        return !harness.tasks().wso2().restRequest().prepareEmptyRequestFromCbl("/t/data.cluster/EXT_DATA_MVCR_IDCARD_CHECK/001")
                .addField("identDocumentId", cardNumber)
                .addField("identDocumentTypeId", "0")
                .post()
                .extract("evidovano")
                .asBoolean();
    }
}
