using UnityEngine;
namespace LitMotion.Extensions
{
    /// 
    /// Provides binding extension methods for SpriteRenderer.
    /// 
    public static class LitMotionSpriteRendererExtensions
    {
        /// 
        /// Create a motion data and bind it to SpriteRenderer.color
        /// 
        /// The type of special parameters given to the motion data
        /// The type of adapter that support value animation
        /// This builder
        /// 
        /// Handle of the created motion data.
        public static MotionHandle BindToColor(this MotionBuilder builder, SpriteRenderer spriteRenderer)
            where TOptions : unmanaged, IMotionOptions
            where TAdapter : unmanaged, IMotionAdapter
        {
            Error.IsNull(spriteRenderer);
            return builder.BindWithState(spriteRenderer, static (x, m) =>
            {
                m.color = x;
            });
        }
        /// 
        /// Create a motion data and bind it to SpriteRenderer.color.r
        /// 
        /// The type of special parameters given to the motion data
        /// The type of adapter that support value animation
        /// This builder
        /// 
        /// Handle of the created motion data.
        public static MotionHandle BindToColorR(this MotionBuilder builder, SpriteRenderer spriteRenderer)
            where TOptions : unmanaged, IMotionOptions
            where TAdapter : unmanaged, IMotionAdapter
        {
            Error.IsNull(spriteRenderer);
            return builder.BindWithState(spriteRenderer, static (x, m) =>
            {
                var c = m.color;
                c.r = x;
                m.color = c;
            });
        }
        /// 
        /// Create a motion data and bind it to SpriteRenderer.color.g
        /// 
        /// The type of special parameters given to the motion data
        /// The type of adapter that support value animation
        /// This builder
        /// 
        /// Handle of the created motion data.
        public static MotionHandle BindToColorG(this MotionBuilder builder, SpriteRenderer spriteRenderer)
            where TOptions : unmanaged, IMotionOptions
            where TAdapter : unmanaged, IMotionAdapter
        {
            Error.IsNull(spriteRenderer);
            return builder.BindWithState(spriteRenderer, static (x, m) =>
            {
                var c = m.color;
                c.g = x;
                m.color = c;
            });
        }
        /// 
        /// Create a motion data and bind it to SpriteRenderer.color.b
        /// 
        /// The type of special parameters given to the motion data
        /// The type of adapter that support value animation
        /// This builder
        /// 
        /// Handle of the created motion data.
        public static MotionHandle BindToColorB(this MotionBuilder builder, SpriteRenderer spriteRenderer)
            where TOptions : unmanaged, IMotionOptions
            where TAdapter : unmanaged, IMotionAdapter
        {
            Error.IsNull(spriteRenderer);
            return builder.BindWithState(spriteRenderer, static (x, m) =>
            {
                var c = m.color;
                c.b = x;
                m.color = c;
            });
        }
        /// 
        /// Create a motion data and bind it to SpriteRenderer.color.a
        /// 
        /// The type of special parameters given to the motion data
        /// The type of adapter that support value animation
        /// This builder
        /// 
        /// Handle of the created motion data.
        public static MotionHandle BindToColorA(this MotionBuilder builder, SpriteRenderer spriteRenderer)
            where TOptions : unmanaged, IMotionOptions
            where TAdapter : unmanaged, IMotionAdapter
        {
            Error.IsNull(spriteRenderer);
            return builder.BindWithState(spriteRenderer, static (x, m) =>
            {
                var c = m.color;
                c.a = x;
                m.color = c;
            });
        }
    }
}