// Copyright HyperTwist, Inc. All Rights Reserved.

#pragma once

#include "HyperTwistTraining/HyperTwistTrainingRepositoryLibrary.h"

namespace HyperTwistTrainingRepositoryLibraryInternal
{
	int32 CompareUtcStrings(const FString& Left, const FString& Right);

	FString ResolveReferenceUtc(const FString& ReferenceUtc);

	int32 ComputeElapsedMilliseconds(const FString& OlderUtc, const FString& NewerUtc);

	FHyperTwistTrainingCoachMemorySnapshot DeriveQueueRecoveryBiasSnapshot(
		const FHyperTwistTrainingRepositoryState& RepositoryState,
		const FString& UserId,
		const FString& ReferenceUtc
	);

	int32 ComputePlanDurationMs(
		const FHyperTwistTrainingReviewPlanState& ReviewPlan,
		const FString& ReferenceUtc
	);

	FHyperTwistTrainingReviewPlanState NormalizeReviewPlanState(
		const FHyperTwistTrainingReviewPlanState& ReviewPlan
	);

	int32 ResolvePolicyCaseLimit(
		const FHyperTwistTrainingReviewPolicy& ReviewPolicy,
		int32 RequestedMaxCases
	);

	bool ContainsLaunchBudgetBroadeningHint(const FString& ReasonLine);

	bool ContainsLaunchBudgetTighteningHint(const FString& ReasonLine);

	TArray<FString> DeduplicateCaseIds(const TArray<FString>& CaseIds);

	void ResolveCoachActionPlanPreferenceDefaults(
		const FHyperTwistCoachBrief& CoachBrief,
		const FHyperTwistTrainingCoachMemorySnapshot& CoachMemorySnapshot,
		EHyperTwistTrainingDeliveryMode& InOutMode,
		EHyperTwistTrainingSelectionPolicy& InOutSelectionPolicy
	);

	TArray<FString> ResolveCoachActionPlanFocusCaseIds(
		const FHyperTwistCoachBrief& CoachBrief,
		const TArray<FString>& LaunchedCaseIds,
		int32 PlannedLaunchCaseCount
	);

	FHyperTwistTrainingCoachActionPlan NormalizeCoachActionPlan(
		const FHyperTwistTrainingCoachActionPlan& ActionPlan
	);

	bool IsTerminalCoachQueueEntryState(EHyperTwistTrainingCoachSessionQueueEntryState EntryState);

	FString MakeCoachSessionQueueEntryFingerprint(
		const FHyperTwistTrainingCoachSessionQueueStateEntry& Entry
	);

	FHyperTwistTrainingCoachSessionQueueState NormalizeCoachSessionQueueState(
		const FHyperTwistTrainingCoachSessionQueueState& QueueState
	);

	bool DidCoachSessionQueueEntryChange(
		const FHyperTwistTrainingCoachSessionQueueStateEntry& PreviousEntry,
		const FHyperTwistTrainingCoachSessionQueueStateEntry& CurrentEntry
	);

	FHyperTwistTrainingCoachSessionQueueHistoryEntry BuildCoachSessionQueueHistoryEntry(
		const FHyperTwistTrainingCoachSessionQueueState& QueueState,
		const FHyperTwistTrainingCoachSessionQueueStateEntry& CurrentEntry,
		const FHyperTwistTrainingCoachSessionQueueStateEntry* PreviousEntry
	);

	FHyperTwistTrainingCoachActionClosureSummary DeriveCoachActionClosureSummaryWithCoachMemory(
		const FHyperTwistTrainingRepositoryState& RepositoryState,
		const FHyperTwistTrainingCoachActionPlan& AnchorPlan,
		const FString& ReferenceUtc,
		const FHyperTwistTrainingCoachMemorySnapshot& CoachMemorySnapshot
	);
}
