Park/Goals/GoalGroup.cs
using System.Collections.Immutable;

namespace HC3;

/// <summary>
/// Defines a grouping of <see cref="Goal"/> -- think of this like a level or stage in the park's progression.
/// </summary>
public sealed partial class GoalGroup : Component
{
	public sealed record SaveData( string Name, ImmutableArray<Goal.SaveData> Goals );

	[ConVar( "hc3.unlockall", ConVarFlags.Cheat | ConVarFlags.Replicated )]
	public static bool UnlockAll { get; set; } = false;

	[Property] public string Title { get; set; } = "DefaultGoal";
	[Property, TextArea] public string Description { get; set; } = "Default goal description";
	/// <summary>
	/// The next goal manager (prefab) to be activated when this one is completed.
	/// </summary>
	[Property] GoalGroup NextGoalManger { get; set; }
	[Property] public bool IsActiveManager { get; set; } = false;

	[Property] public string Icon { get; set; } = "star";

	bool IsCompleted { get; set; } = false;

	/// <summary>
	/// Get all the goals attached to this goal manager.
	/// </summary>
	public IEnumerable<Goal> GetGoals() => GetComponents<Goal>();

	protected override void OnAwake()
	{
		CheckIsFinished();
	}

	private void CheckIsFinished()
	{
		if ( IsActiveManager )
		{
			//Check all the goals if they are completed, this manager is completed 
			// and the next goal manager is activated
			if ( GetGoals().All( x => x.IsUnlocked() ) )
			{
				SetComplete();
			}
		}
	}

	/// <summary>
	/// Set this goal manager as completed.
	/// </summary>
	public void SetComplete()
	{
		IsActiveManager = false;
		IsCompleted = true;

		if ( !NextGoalManger.IsValid() )
			return;

		NextGoalManger.IsActiveManager = true;
	}

	protected override void OnFixedUpdate()
	{
		CheckIsFinished();
	}
}