// FlexiMotion // https://kybernetik.com.au/flexi-motion // Copyright 2023-2025 Kybernetik //

using System;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;

namespace FlexiMotion.Jobs
{
    /// <summary>Initializes <see cref="JobScheduller.GetInstance"/>.</summary>
    /// https://kybernetik.com.au/flexi-motion/api/FlexiMotion.Jobs/JobSchedullerInitializer
    /// 
    public class JobSchedullerInitializer
    {
#if UNITY_EDITOR
        [UnityEditor.InitializeOnLoadMethod]
#endif
        [RuntimeInitializeOnLoadMethod]
        private static void Initialize()
        {
            JobScheduller.GetInstance = updateMode =>
            {
                switch (updateMode)
                {
                    case AnimatorUpdateMode.Normal: return ComponentSingleton<JobSchedullerLateUpdate>.Instance;
                    case AnimatorUpdateMode.AnimatePhysics: return ComponentSingleton<JobSchedullerFixedUpdate>.Instance;
                    case AnimatorUpdateMode.UnscaledTime: return ComponentSingleton<JobSchedullerLateUpdateUnscaled>.Instance;
                    default: throw new ArgumentException(
                        $"Unsupported {nameof(AnimatorUpdateMode)}: {updateMode}", nameof(updateMode));
                }
            };
        }
    }
}
