import Action from "./Action";
import Answer from "./Answer";
import Interaction from "./Interaction";
import Question from "./Question";

export default class InteractionFactory {

    public static parseInteraction(value: string): Interaction {
        if (value.includes("?")) {
            const [test, answer] = value.split("?");
            return new Answer(new Question(test), answer === "true");
        } else if (value.includes("$")) {
            const [prefix, suffix] = value.split("$");
            return new Action(prefix, suffix);
        } else {
            return new Action(value);
        }

    }

    public createAction(prefix: string, suffix?: string) {
        if (suffix) {
            return new Action(prefix, suffix);
        } else {
            return new Action(prefix);
        }
    }

}
