using System.Linq;
using Sirenix.OdinInspector;
using UnityEngine;

namespace VOID.Generic.AreaOfEffect
{
    [TypeRegistryItem("Sphere")]
    public class SphereAreaOfEffect : AbstractAreaOfEffect
    {
        [SerializeField, Required, MinValue(0.5)]
        private float radius;

        public override Mesh GetMesh()
        {
            var sphereMesh = Resources.GetBuiltinResource<Mesh>("Cylinder.fbx");

            var mesh = new Mesh();
            mesh.vertices = sphereMesh.vertices.Select(vertex => vertex * radius).ToArray();
            mesh.triangles = sphereMesh.triangles;
            mesh.uv = sphereMesh.uv;
            mesh.normals = sphereMesh.normals;
            mesh.colors = sphereMesh.colors;
            mesh.tangents = sphereMesh.tangents;
            
            return mesh;
        }

        public override Collider AddCollider(GameObject gameObject)
        {
            var collider = gameObject.AddComponent<SphereCollider>();
            collider.isTrigger = true;
            collider.radius = radius;

            return collider;
        }
    }
}