
import InteractionFactory from "../domain/InteractionFactory";
import SequenceEvaluation from "../domain/SequenceEvaluation";
import SequenceEvaluator from "../domain/SequenceEvaluator";
import SequenceEvaluatorRepository from "../domain/SequenceEvaluatorRepository";

export default class SequenceEvaluationApplication {

    public sequenceEvaluatorRepository: SequenceEvaluatorRepository;

    constructor(sequenceEvaluatorRepository: SequenceEvaluatorRepository) {
        this.sequenceEvaluatorRepository = sequenceEvaluatorRepository;
    }

    public createSequenceEvaluator(name: string, sessionId: string, stepList: string[]): Promise<void> {
        return this.sequenceEvaluatorRepository.createSequenceEvaluator(name, sessionId, stepList)
            .then((_sequenceEvaluator) => {return; });
    }

    public updateSequenceEvaluator(name: string, sessionId: string, stepList: string[]): Promise<void> {
        return this.sequenceEvaluatorRepository.updateSequenceEvaluator(name, sessionId, stepList)
        .then(() => {return; });
    }

    public removeSequenceEvaluator(sessionId: string): Promise<void> {
        return this.sequenceEvaluatorRepository.removeSequenceEvaluator(sessionId)
        .then(() => {return; });
    }

    public getSequenceEvaluator(sessionId: string): Promise<SequenceEvaluator> {
        return this.sequenceEvaluatorRepository.getSequenceEvaluatorBySessionId(sessionId).then((evaluator) => {
            return evaluator;
        });
    }

    public evaluateSequence(sessionId: string, sequence: string[]): Promise<SequenceEvaluation | null> {
        const interactionList = sequence.map((interactionText) => InteractionFactory.parseInteraction(interactionText));
        return this.sequenceEvaluatorRepository.getSequenceEvaluatorBySessionId(sessionId)
        .then((evaluator) => {
            if (!evaluator) {
                return null;
            }
            return evaluator.evaluate(interactionList);
        });
    }

}
