// This program has been developed by students from the bachelor Computer Science at Utrecht
// University within the Software Project course.
// © Copyright Utrecht University (Department of Information and Computing Sciences)
// This file is to avoid sharing both functions and components which eslint dislikes. :)
import type { GoalNode } from "../nodes/GoalNode"
import type { Goal, Plan } from "./Plan"

/**
 * Inserts a goal into a plan
 * @param plan: plan to insert goal into
 * @param goalNode: the goal node to insert into the plan.
 * @returns: a new plan with the goal inside.
 */
export function insertGoalInPlan(plan: Plan, goalNode: GoalNode): Plan {
    const planElement : Goal = {
        id: goalNode.id,
        type: "goal",
    }

    return {
        ...plan,
        steps: [...plan.steps, planElement],
    }
}


/**
 * Deletes a goal from  a plan
 * @param plan: plan to delete goal from
 * @param goalID: the goal node to delete.
 * @returns: a new plan with the goal removed.
 */
export function deleteGoalInPlanByID(plan: Plan, goalID: string) {
    const updatedPlan = {...plan,
        steps: plan.steps.filter((x) => x.id !== goalID)
    }
    return updatedPlan.steps.length == 0 ? undefined : updatedPlan
}