import Stimulus from "../../../model/src/domain/Stimulus";

export default class Word {

    public static fromStimulus(stimulus: Stimulus): Word {
        const [prefix, suffix] = stimulus.value.split("$");
        if (suffix !== undefined && suffix !== null) {
            return new Word(prefix, suffix);
        } else {
            return new Word(prefix);
        }
    }

    public prefix: string;
    public suffix: string;

    constructor(prefix: string, suffix?: string) {
        this.prefix = prefix;
        this.suffix = suffix;
    }

    public toString(): string {
        if (this.suffix !== null && this.suffix !== undefined) {
            return `${this.prefix}$${this.suffix}`;
        } else {
            return this.prefix;
        }
    }

    public toStimulus(): Stimulus {
        return new Stimulus(this.toString());
    }
}
