using EscapeRoomEngine.Engine.Runtime.Utilities;
using NaughtyAttributes;
using UnityEngine;

namespace EscapeRoomEngine.Desert.Runtime
{
    /// <summary>
    /// A rotating crystal that can change colour.
    /// </summary>
    [RequireComponent(typeof(Emission))]
    public class Crystal : MonoBehaviour
    {
        [Required]
        [BoxGroup("Internal")]
        public Light crystalLight;

        /// <summary>
        /// Turns the crystal light on or off.
        /// </summary>
        public bool Active
        {
            set
            {
                _emission.active = value;
                crystalLight.enabled = value;
            }
        }

        /// <summary>
        /// The crystal light and emission colours.
        /// </summary>
        public DynamicColor Color
        {
            set
            {
                _emission.color = value.hdr;
                crystalLight.color = value.ldr;
            }
        }

        private Emission _emission;

        private void Awake()
        {
            _emission = GetComponent<Emission>();
        }
    }
}