using UnityEngine;

namespace AlterchaseSDK
{
    [CreateAssetMenu(fileName = "New Model Mod", menuName = "Alterchase SDK/Model Mod Asset", order = 1)]
    public class ModelModAsset : ModAsset
    {
        [Header("Model Configuration")]
        [SerializeField] private GameObject modelPrefab;
        [SerializeField] private ModelCategory category = ModelCategory.Prop;
        [SerializeField] private bool isInteractable = false;
        [SerializeField] private bool hasPhysics = true;
        [SerializeField] private float mass = 1f;
        [SerializeField] private Material[] materials;
        [SerializeField] private Vector3 boundingBoxSize = Vector3.one;
        [SerializeField] private bool canBeDestroyed = false;
        [SerializeField] private GameObject destructionPrefab;
        [SerializeField] private AudioClip[] soundEffects;

        public GameObject ModelPrefab => modelPrefab;
        public ModelCategory Category => category;
        public bool IsInteractable => isInteractable;
        public bool HasPhysics => hasPhysics;
        public float Mass => mass;
        public Material[] Materials => materials;
        public Vector3 BoundingBoxSize => boundingBoxSize;
        public bool CanBeDestroyed => canBeDestroyed;
        public GameObject DestructionPrefab => destructionPrefab;
        public AudioClip[] SoundEffects => soundEffects;

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

        public override bool ValidateAsset(out string errorMessage)
        {
            if (modelPrefab == null)
            {
                errorMessage = "Model prefab is not assigned.";
                return false;
            }

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

            if (hasPhysics && mass <= 0f)
            {
                errorMessage = "Mass must be greater than 0 when physics is enabled.";
                return false;
            }

            errorMessage = string.Empty;
            return true;
        }
    }

    public enum ModelCategory
    {
        Prop,
        Furniture,
        Vehicle,
        Decoration,
        Interactive,
        Collectible,
        Environment,
        Other
    }
}
