using Newtonsoft.Json;
using System.Collections.Generic;
using UnityEngine;
namespace Tool.ReadChecker
{
    public class ReadLog
    {
        private string ModuleName { get; set; }

        [JsonProperty]
        private List<string> FileTypeNotAllowedList { get; set; } = new();
        [JsonProperty]
        private List<string> FileNameNotAllowedList { get; set; } = new();

        [JsonProperty]
        private List<string> FolderNameNotAllowedList { get; set; } = new();
        [JsonProperty]
        private List<string> MissingForlderOrFileList { get; set; } = new();
        [JsonIgnore]
        public string CurModuleId { get; set; }
        [JsonIgnore]
        public string Tag => $"[{ModuleName}][{CurModuleId}]";
        [JsonIgnore]
        public bool ShowUnityDebug { get; set; } = true;
        public bool LogOn { get; set; } = true;
        public ReadLog(string name)
        {
            ModuleName = name;
        }

        private void ShowLog(string log)
        {
            if (ShowUnityDebug)
                Debug.Log(log);
        }

        public void Log(string str)
        {
            if (LogOn)
            {
                var log = $"[{ModuleName}][{CurModuleId}]:{str}";
                Debug.Log(log);
            }
        }
        public void AddFileTypeWarning(string str)
        {
            string log = $"[warning]{Tag}FileTypeNotAllowed:{str}";
            FileTypeNotAllowedList.Add(log);
            ShowLog(log);
        }
        public void AddFileNameWarning(string path)
        {
            string log = $"[warning]{Tag}FileNameNotAllowed:{path}";
            FileNameNotAllowedList.Add(log);
            ShowLog(log);
        }

        public void AddFolderNameWarning(string path)
        {
            string log = $"[warning]{Tag}FolderNameNotAllowed:{path}";
            FolderNameNotAllowedList.Add(log);
            ShowLog(log);
        }

        public void AddFolderMissingError(string path)
        {
            string log = $"[Error]{Tag}FolderIsMissing:{path}";
            MissingForlderOrFileList.Add(log);
            ShowLog(log);
        }

        public void AddFileMissingError(string path)
        {
            string log = $"[Error]{Tag}FileIsMissing:{path}";
            MissingForlderOrFileList.Add(log);
            ShowLog(log);
        }

        public string SaveToJson()
        {
            string json = JsonConvert.SerializeObject(this, Formatting.Indented);
            return json;
        }
        public void Clear()
        {
            FileTypeNotAllowedList.Clear();
            FileNameNotAllowedList.Clear();
            MissingForlderOrFileList.Clear();
        }
    }
}