using Unity.Netcode;
using UnityEngine;
using Unity.BossRoom.Gameplay.GameplayObjects.Character;

[CreateAssetMenu(menuName = "Abilities/CrowsForesight")]
public class CrowsForesightAbility : Ability
{
    public override void Execute(ServerCharacter character, Vector3 targetPosition, Vector3 targetRotation)
    {
        if (!NetworkManager.Singleton.IsServer)
        {
            Debug.LogError("[CrowsForesightAbility] Execute should only be called on the server.");
            return;
        }

        Debug.Log($"[CrowsForesightAbility] Spawning foresight prefab for Crow {character.OwnerClientId}");

        GameObject foresightInstance = Instantiate(GetPrefab(), character.transform.position, Quaternion.identity);
        NetworkObject netObj = foresightInstance.GetComponent<NetworkObject>();

        if (netObj)
        {
            netObj.Spawn();
            CrowsForesightPrefab foresightPrefab = foresightInstance.GetComponent<CrowsForesightPrefab>();
            foresightPrefab.Initialize(CrowManager.Instance.GetCurrentCrow().OwnerClientId, this);
            Debug.Log($"[CrowsForesightAbility] Assigned foresight prefab to Crow {character.OwnerClientId}");
        }
    }

}