using System;
using System.IO;
using UnityEngine;

public static class Logger
{
	public enum LogLevel
	{
		Info,
		Warning,
		Error
	}

	private static readonly string logFilePath = Path.Combine(Application.persistentDataPath, "log3.txt");

	public static void Log(string message, LogLevel level = LogLevel.Info)
	{
		try
		{
			WriteLogToFile(FormatLogMessage(message, level));
		}
		catch (Exception ex)
		{
			Debug.LogError("Failed to log message: " + ex.Message);
		}
	}

	private static string FormatLogMessage(string message, LogLevel level)
	{
		string arg = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
		return $"{arg} [{level}] {message}";
	}

	private static void WriteLogToFile(string message)
	{
		using StreamWriter streamWriter = new StreamWriter(logFilePath, append: true);
		streamWriter.WriteLine(message);
	}

	public static void ClearLog()
	{
		try
		{
			File.Delete(logFilePath);
		}
		catch (Exception ex)
		{
			Debug.LogError("Failed to clear log file: " + ex.Message);
		}
	}
}
