using UnityEngine;

[CreateAssetMenu(fileName = "New Debug Channel", menuName = "Scriptables/Debug Channel")]
public class DebugChannelSO : ScriptableObject
{
	[Header("Console Messages")]
    [SerializeField] bool m_enableDebugMessages;
	public bool DebugMessagesEnabled { get { return m_enableDebugMessages; } }
    
	[SerializeField] bool m_enableErrorBreakPoints;
	public bool ErrorBreakPointsEnabled{get{return m_enableErrorBreakPoints;}}

	[Header("Visuals")]
    [SerializeField] bool m_enableDebugGizmos;
    public bool DebugGizmosEnabled { get { return m_enableDebugGizmos; } }

    [SerializeField] Color m_channelDisplayColor = Color.black;
    public Color ChannelDisplayColor { get { return m_channelDisplayColor; } }

    public enum Severity
    {
        Log,
        Warning,
        Error
    }

    public void Raise(string _message, Severity _severity = Severity.Log)
    {
        if (!m_enableDebugMessages)
            return;

        _message += "\n ";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_message);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_message);
                break;
            case (Severity.Error):
                Debug.LogError(_message);
                break;
        }
    }
    public void Raise(string[] _messages, Severity _severity = Severity.Log)
    {
        if (!m_enableDebugMessages)
            return;

        string _finalMessage = "";

        foreach (string _message in _messages)
            _finalMessage += _message + "\n";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }
    public void Raise(string _sourceType, string _message, Severity _severity = Severity.Log)
    {
        if (!m_enableDebugMessages)
            return;

        string _finalMessage = 
            "<b>[<color=#" + ColorUtility.ToHtmlStringRGBA(m_channelDisplayColor) + ">" +
            _sourceType + 
            "</color>]</b> " +
            _message + 
            "\n ";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }
    public void Raise(string _sourceType, string[] _messages, Severity _severity = Severity.Log)
    {
        if (!m_enableDebugMessages)
            return;

        string _finalMessage = 
            "<b>[<color=#" + ColorUtility.ToHtmlStringRGBA(m_channelDisplayColor) + ">" +
            _sourceType +
            "</color>]</b> ";

        foreach (string _message in _messages)
            _finalMessage += _message + "\n";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }
    public void Raise(Object _sourceType, string _message, Severity _severity = Severity.Log)
    {
        if (!m_enableDebugMessages)
	        return;
            
	    string _combinedMessage = 
		    "<b>[<color=#" + ColorUtility.ToHtmlStringRGBA(m_channelDisplayColor) + ">" + 
		    _sourceType.GetType().ToString() + "</color>]</b> " + 
		    _message + "\n ";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_combinedMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_combinedMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_combinedMessage);
                break;
        }
    }
    public void Raise(Object _sourceType, string[] _messages, Severity _severity = Severity.Log)
    {
        if (!m_enableDebugMessages)
            return;

	    string _finalMessage = 
		    "<b>[<color=#" + ColorUtility.ToHtmlStringRGBA(m_channelDisplayColor) + ">" + 
		    _sourceType.GetType().ToString() + 
		    "</color>]</b> ";

        foreach (string _message in _messages)
            _finalMessage += _message + "\n";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }

    public static void OverrideRaise(string _sourceType, string _message, Color _color, Severity _severity = Severity.Log)
    {
        string _finalMessage = 
            "<b>[<color=#" + ColorUtility.ToHtmlStringRGBA(_color) + ">" + 
            _sourceType + 
            "</color>]</b> " + 
            _message + 
            "\n ";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }
    public static void OverrideRaise(string _sourceType, string _message, Severity _severity = Severity.Log)
    {
        string _finalMessage = 
            "<b>[" + 
            _sourceType + 
            "]</b> " + 
            _message + 
            "\n ";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }
    public static void OverrideRaise(string _sourceType, string[] _messages, Severity _severity = Severity.Log)
    {
        string _finalMessage = 
            "<b>[" + 
            _sourceType + 
            "]</b> ";

        foreach (string _message in _messages)
            _finalMessage += _message + "\n";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }
    public static void OverrideRaise(string _sourceType, string[] _messages, Color _color, Severity _severity = Severity.Log)
    {
        string _finalMessage = 
            "<b>[<color=#" + ColorUtility.ToHtmlStringRGBA(_color) + ">" + 
            _sourceType + 
            "</color>]</b> ";

        foreach (string _message in _messages)
            _finalMessage += _message + "\n";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }
    public static void OverrideRaise(Object _sourceType, string _message, Color _color, Severity _severity = Severity.Log)
    {
	    string _finalMessage = 
		    "<b>[<color=#" + ColorUtility.ToHtmlStringRGBA(_color) + ">" + 
		    _sourceType.GetType().ToString() + 
		    "</color>]</b> " + 
		    _message + 
		    "\n ";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }
    public static void OverrideRaise(Object _sourceType, string _message, Severity _severity = Severity.Log)
    {
	    string _finalMessage = 
		    "<b>[" + 
		    _sourceType.GetType().ToString() + 
		    "]</b> " + 
		    _message + 
		    "\n ";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }
    public static void OverrideRaise(Object _sourceType, string[] _messages, Severity _severity = Severity.Log)
    {
	    string _finalMessage = 
		    "<b>[" + 
		    _sourceType.GetType().ToString() + 
		    "]</b> ";

        foreach (string _message in _messages)
            _finalMessage += _message + "\n";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }
    public static void OverrideRaise(Object _sourceType, string[] _messages, Color _color, Severity _severity = Severity.Log)
    {
	    string _finalMessage = 
		    "<b>[<color=#" + ColorUtility.ToHtmlStringRGBA(_color) + " > " + 
		    _sourceType.GetType().ToString() + 
		    "</color>]</b> ";

        foreach (string _message in _messages)
            _finalMessage += _message + "\n";

        switch (_severity)
        {
            case (Severity.Log):
                Debug.Log(_finalMessage);
                break;
            case (Severity.Warning):
                Debug.LogWarning(_finalMessage);
                break;
            case (Severity.Error):
                Debug.LogError(_finalMessage);
                break;
        }
    }
    
	public void DrawGizmoRay(Vector3 _origin, Vector3 _normal, float _length = 1){
		if (!m_enableDebugGizmos)
			return;
		
		Gizmos.color = m_channelDisplayColor;
		
		Gizmos.DrawLine(_origin, _origin + _normal.normalized * _length);
	}
	
	public void DrawGizmoRay(Vector3 _origin, Vector3 _normal, Color _color, float _length = 1){
		if (!m_enableDebugGizmos)
			return;
		
		Gizmos.color = _color;
		
		Gizmos.DrawLine(_origin, _origin + _normal.normalized * _length);
	}
	public void DrawGizmoSphere(Vector3 _origin, float _radius = 1){
		if (!m_enableDebugGizmos)
			return;
		
		Gizmos.color = m_channelDisplayColor;
		
		Gizmos.DrawSphere(_origin, _radius);
	}
	
	public void DrawGizmoSphere(Vector3 _origin, Color _color, float _radius = 1){
		if (!m_enableDebugGizmos)
			return;
		
		Gizmos.color = _color;
		
		Gizmos.DrawSphere(_origin, _radius);
	}
	
	public void DrawGizmoIcon(Vector3 _origin, string _name){
		if (!m_enableDebugGizmos)
			return;
		
		Gizmos.color = m_channelDisplayColor;
		
		Gizmos.DrawIcon(_origin, _name, false);
	}
}
