#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "ZMMOJobTypes.h"
#include "ZMMOJobsLibrary.generated.h"

class UZMMOJobDataAsset;

/**
 *  Helpers Blueprint pra UI/HUD acessar dados de job sem precisar pegar o
 *  Subsystem manualmente. Todos usam WorldContextObject pra resolver
 *  GameInstance → Subsystem internamente.
 *
 *  Padrao de uso em UMG:
 *   - Text binding: `JobsLibrary::GetJobDisplayName(Self, AttrComp.Current.ClassId)`
 *   - Image binding: `JobsLibrary::GetJobIcon(Self, ClassId).LoadSynchronous()`
 */
UCLASS()
class ZMMOJOBS_API UZMMOJobsLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
	/// Nome localizado do job. Fallback "Classe N" se ClassId nao tem DA
	/// correspondente (job nao registrado no Content/ZMMO/Data/Jobs/).
	UFUNCTION(BlueprintPure, Category = "Zeus|Jobs",
		meta = (WorldContext = "WorldContextObject"))
	static FText GetJobDisplayName(const UObject* WorldContextObject, int32 ClassId);

	/// DataAsset completo (pode ser nullptr — caller checa).
	UFUNCTION(BlueprintPure, Category = "Zeus|Jobs",
		meta = (WorldContext = "WorldContextObject"))
	static UZMMOJobDataAsset* GetJobData(const UObject* WorldContextObject, int32 ClassId);

	/// Helper de UI: retorna true se ClassId tem DA registrado.
	UFUNCTION(BlueprintPure, Category = "Zeus|Jobs",
		meta = (WorldContext = "WorldContextObject"))
	static bool IsJobRegistered(const UObject* WorldContextObject, int32 ClassId);

	/// Lista jobs num tier (UI dropdown). Vazio se subsystem indisponivel.
	UFUNCTION(BlueprintPure, Category = "Zeus|Jobs",
		meta = (WorldContext = "WorldContextObject"))
	static TArray<UZMMOJobDataAsset*> GetJobsByTier(
		const UObject* WorldContextObject, EZMMOJobTier Tier);

	/// Destinos de promocao a partir do char atual. WBP de promocao consome
	/// direto. Vazio se nao houver filhos (ex: char ja' esta em Tier 3
	/// Mastery — Jobs.4 introduzira terminal de progressao).
	UFUNCTION(BlueprintPure, Category = "Zeus|Jobs",
		meta = (WorldContext = "WorldContextObject"))
	static TArray<UZMMOJobDataAsset*> GetEligibleNextJobs(
		const UObject* WorldContextObject, int32 CurrentClassId);

	/// Helper de send via ZeusNetworkSubsystem. Conveniencia pra WBP nao
	/// precisar pegar o subsystem manualmente. Idempotente: rejeitado
	/// silenciosamente se nao conectado.
	UFUNCTION(BlueprintCallable, Category = "Zeus|Jobs",
		meta = (WorldContext = "WorldContextObject"))
	static void SendJobChangeRequest(
		const UObject* WorldContextObject, int32 TargetClassId);
};
