import fetch from "node-fetch";
import config from "../config";

const URL: string = `http://${config.constraint.host}:${config.constraint.port}/checkSequenceValidity/`;

export default class ExplorationConstraintREST {

    public setSequenceConstraintSet(sessionId, constraints): Promise<void> {

        const options = {
            method: "POST",
            body:    JSON.stringify({
                sessionId,
                constraints,
            }),
            headers: { "Content-Type": "application/json" },
        };

        return new Promise((resolve, reject) => {
            fetch(URL, options)
            .then( (response) => {
                if (response.ok) {
                    resolve();
                } else {
                    reject("Failed to set constraints");
                }
            })
            .catch((error) => {
                reject(error);
            });
        });
    }

}
