using System;

using RobocraftX.Blocks;
using RobocraftX.Common;
using Svelto.ECS;
using Unity.Mathematics;

using GamecraftModdingAPI.Utility;

namespace GamecraftModdingAPI.Blocks
{
	public class Servo : SignalingBlock
    {
		public Servo(EGID id) : base(id)
        {
        }

		public Servo(uint id) : base(new EGID(id, CommonExclusiveGroups.SERVO_BLOCK_GROUP))
        {
        }

        // custom servo properties

        /// <summary>
        /// The servo's minimum angle.
        /// </summary>
        public float MinimumAngle
        {
	        get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.minDeviation);

			set
			{
				BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, float val) => st.minDeviation = val, value);
			}
		}

		/// <summary>
        /// The servo's maximum angle.
        /// </summary>
        public float MaximumAngle
        {
			get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.maxDeviation);

			set
			{
				BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, float val) => st.maxDeviation = val, value);
			}
        }

		/// <summary>
        /// The servo's maximum force.
        /// </summary>
        public float MaximumForce
        {
			get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.servoVelocity);

			set
			{
				BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, float val) => st.servoVelocity = val, value);
			}
        }

		/// <summary>
        /// The servo's direction.
        /// </summary>
        public bool Reverse
        {
			get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.reverse);

			set
			{
				BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, bool val) => st.reverse = val, value);
			}
        }
    }
}