using UnityEngine;

namespace AlterchaseSDK.Examples
{
    public class PlayerSpawnExample : MonoBehaviour
    {
        [Header("Game's Player Prefab")]
        [Tooltip("This is YOUR game's player prefab - not included in the SDK")]
        [SerializeField] private GameObject gamePlayerPrefab;

        private void Start()
        {
            SpawnPlayerAtReference();
        }

        private void SpawnPlayerAtReference()
        {
            PlayerSpawnReference spawnRef = PlayerSpawnReference.FindSpawnReference();

            if (spawnRef == null)
            {
                Debug.LogWarning("No PlayerSpawnReference found in the modded level. Using default spawn.");
                return;
            }

            if (gamePlayerPrefab == null)
            {
                Debug.LogError("Game player prefab is not assigned!");
                return;
            }

            GameObject player = Instantiate(
                gamePlayerPrefab, 
                spawnRef.SpawnPosition, 
                spawnRef.SpawnRotation
            );

            Debug.Log($"Player spawned at position: {spawnRef.SpawnPosition}");
        }
    }
}
