import Action from "./Action";
import Exploration from "./Exploration";

// Aggregate
export default class Session {
    private _id: string;
    private _explorationList: Exploration[];

    constructor(id: string) {
        if (id === undefined || id === null) {
            throw new Error("Cannot create Session with undefined or null id");
        }
        this._id = id;
        this._explorationList = [];
    }

    get id() {
        return this._id;
    }
    
    get numberOfExploration() {
        return this._explorationList.length;
    }

    get explorationList() {
        return this._explorationList.slice();
    }

    public startExploration(): number {
        const explorationNumber = this._explorationList.length;
        const exploration: Exploration = new Exploration(explorationNumber);
        this._explorationList.push(exploration);
        return explorationNumber;
    }

    public addActionToExploration(explorationNumber: number, action: Action): void {
        if (explorationNumber < 0 || explorationNumber >= this._explorationList.length) {
            throw new Error("cannot add action to exploration, wrong explorationNumber.");
        }
        const exploration = this._explorationList[explorationNumber];
        exploration.addAction(action);
    }

    
    public addActionListToExploration(explorationNumber: number, actionList: Action[]): void {
        if (explorationNumber < 0 || explorationNumber >= this._explorationList.length) {
            throw new Error("cannot add comment to exploration, wrong explorationNumber.");
        }
        const exploration = this._explorationList[explorationNumber];
        exploration.addActionList(actionList);
    }

    public getActionListOfExploration(explorationNumber: number): Action[] {
        if (explorationNumber < 0 || explorationNumber >= this._explorationList.length) {
            throw new Error("cannot add return ActionList to exploration, wrong explorationNumber.");
        }
        return this._explorationList[explorationNumber].actionList;
    }

}
