using UnityEngine;

namespace AlterchaseSDK
{
    [CreateAssetMenu(fileName = "New Level Mod", menuName = "Alterchase SDK/Level Mod Asset", order = 0)]
    public class LevelModAsset : ModAsset
    {
        [Header("Level Configuration")]
        [SerializeField] private Object sceneAsset;
        [SerializeField] private string scenePath;
        [SerializeField] private Texture2D levelPreview;
        [SerializeField] private LevelDifficulty difficulty = LevelDifficulty.Medium;
        [SerializeField] private float estimatedCompletionTime = 300f;
        [SerializeField] private string[] levelTags;
        [SerializeField] private bool supportsMultiplayer = false;
        [SerializeField] private Vector3 playerSpawnPoint = Vector3.zero;
        [SerializeField] private AudioClip ambientMusic;

        public string ScenePath => scenePath;
        public Texture2D LevelPreview => levelPreview;
        public LevelDifficulty Difficulty => difficulty;
        public float EstimatedCompletionTime => estimatedCompletionTime;
        public string[] LevelTags => levelTags;
        public bool SupportsMultiplayer => supportsMultiplayer;
        public Vector3 PlayerSpawnPoint => playerSpawnPoint;
        public AudioClip AmbientMusic => ambientMusic;

        public override ModAssetType GetAssetType() => ModAssetType.Level;

        public override bool ValidateAsset(out string errorMessage)
        {
            if (string.IsNullOrEmpty(scenePath))
            {
                errorMessage = "Scene path is not set. Please assign a scene asset.";
                return false;
            }

            if (string.IsNullOrEmpty(assetName))
            {
                errorMessage = "Level name cannot be empty.";
                return false;
            }

            errorMessage = string.Empty;
            return true;
        }

        public override void OnValidate()
        {
            base.OnValidate();
#if UNITY_EDITOR
            if (sceneAsset != null)
            {
                scenePath = UnityEditor.AssetDatabase.GetAssetPath(sceneAsset);
            }
#endif
        }
    }

    public enum LevelDifficulty
    {
        Easy,
        Medium,
        Hard,
        Expert,
        Nightmare
    }
}
