using UnityEngine;

namespace Yodo1.MAS
{
    /// <summary>
    /// Log levels for the Yodo1 MAS SDK. The runtime threshold is <see cref="Yodo1U3dLog.Level"/>;
    /// a log is emitted only when its level is at or below the threshold.
    /// </summary>
    public enum Yodo1LogLevel
    {
        None = 0,
        Error = 1,
        Warning = 2,
        Info = 3,
        Verbose = 4,
    }

    /// <summary>
    /// Centralized logging for the Yodo1 MAS SDK.
    /// All MAS logs go through this class so they share a single tag and can be
    /// filtered at runtime via <see cref="Level"/>. Warnings and errors are only
    /// silenced when <see cref="Level"/> is set below their level.
    /// </summary>
    public static class Yodo1U3dLog
    {
        public const string Tag = "[Yodo1Mas] ";

        public static Yodo1LogLevel Level { get; set; } = Yodo1LogLevel.Info;

        public static void LogVerbose(string message)
        {
            if (Level >= Yodo1LogLevel.Verbose)
            {
                Debug.Log(Tag + message);
            }
        }

        public static void LogVerbose(string format, params object[] args)
        {
            if (Level >= Yodo1LogLevel.Verbose)
            {
                Debug.Log(Tag + string.Format(format, args));
            }
        }

        public static void LogInfo(string message)
        {
            if (Level >= Yodo1LogLevel.Info)
            {
                Debug.Log(Tag + message);
            }
        }

        public static void LogInfo(string format, params object[] args)
        {
            if (Level >= Yodo1LogLevel.Info)
            {
                Debug.Log(Tag + string.Format(format, args));
            }
        }

        public static void LogWarning(string message)
        {
            if (Level >= Yodo1LogLevel.Warning)
            {
                Debug.LogWarning(Tag + message);
            }
        }

        public static void LogWarning(string format, params object[] args)
        {
            if (Level >= Yodo1LogLevel.Warning)
            {
                Debug.LogWarning(Tag + string.Format(format, args));
            }
        }

        public static void LogError(string message)
        {
            if (Level >= Yodo1LogLevel.Error)
            {
                Debug.LogError(Tag + message);
            }
        }

        public static void LogError(string format, params object[] args)
        {
            if (Level >= Yodo1LogLevel.Error)
            {
                Debug.LogError(Tag + string.Format(format, args));
            }
        }

        public static void LogException(System.Exception exception)
        {
            if (Level >= Yodo1LogLevel.Error)
            {
                Debug.LogException(exception);
            }
        }
    }
}
