using System;
using UnityEngine;

namespace pdinklag.CPW.Common
{
    public abstract class CAWMesh : MonoBehaviour
    {
        [Serializable]
        public class BlendShape
        {
            [Tooltip("The name of the corresponding blend shape.")]
            public string Name;

            [Tooltip("The blend shape category, if any.")]
            public string Category;

            [Tooltip("The weight range allowed for the blend shape.")]
            public MinMax WeightRange = new MinMax(0, 100);

            [Tooltip("The default weight.")]
            public float DefaultWeight = 0;

            [Tooltip("How much one unit of this blend shape will add to the wrestler's body weight.")]
            public float BodyWeight = 0;
        }

        [Serializable]
        public class MeshEntry
        {
            [Tooltip("The mesh renderer.")]
            public SkinnedMeshRenderer Renderer;

            [Tooltip("The (quantized) vertices of the base mesh that this mesh occludes.")]
            [HideInInspector] // nb: occlusion editing is handled explicitly by CAWMeshEditor
            public Vector3Int[] Occlusion;

            public bool HasOcclusionData => Occlusion != null && Occlusion.Length > 0;
        }

        [Header("Component Specific")]
        [Tooltip("The components' meshes.")]
        public MeshEntry[] Meshes;

        [Tooltip("The index of the material to paint on.")]
        public int PaintMaterialIndex = 0;

        [Tooltip("The paint resolution - the larger the nicer, but also the larger the CAW file; the final atlas size is also limited.")]
        public CAWPaintResolution PaintResolution = CAWPaintResolution.Medium;

        [Tooltip("The blend shapes specifically for this component.")]
        public BlendShape[] BlendShapes;

        private void Start()
        {
            foreach (var m in Meshes)
            {
                m.Renderer.updateWhenOffscreen = true;
            }
        }
    }
}
