package cn.com.qmth.examcloud.core.questions.service.bean.context;

import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
import cn.com.qmth.examcloud.core.questions.service.bean.condition.Condition;
import cn.com.qmth.examcloud.core.questions.service.bean.valve.Valve;

import java.util.*;

public abstract class Context implements Valve {

    protected List<Valve> valves;

    protected List<Condition> conditions;

    protected Set<Question> selectQues;

    public Context(List<Condition> conditions) {
        this.valves = new LinkedList<>();
        this.conditions = new LinkedList<>();
        this.selectQues = new HashSet<>();

        if (conditions != null) {
            this.conditions.addAll(conditions);
        }
    }

    public boolean check(Question question) {
        for (Valve valve : valves) {
            if (!valve.check(question)) {
                return false;
            }
        }
        return true;

    }

    public void select(Question question) {
        for (Valve valve : valves) {
            valve.select(question);
        }
        selectQues.add(question);
    }

    public abstract boolean finish();

    public Map<String, String> status() {
        return null;

    }

    public void reset() {

    }

    public List<Valve> getValves() {
        return valves;
    }

    public void setValves(List<Valve> valves) {
        this.valves = valves;
    }

    public List<Condition> getConditions() {
        return conditions;
    }

    public void setConditions(List<Condition> conditions) {
        this.conditions = conditions;
    }

    public Set<Question> getSelectQues() {
        return selectQues;
    }

    public void setSelectQues(Set<Question> selectQues) {
        this.selectQues = selectQues;
    }

}
