using System.Collections.Generic;
using System.IO;
using UnityEditor;

namespace Tool.ReadChecker
{
    public class Poetry_ExerciseChecker 
    {
        [MenuItem("Tool/ReadChecker/Poetry/CheckExercise")]
        public static void CheckeExerciseModel()
        {
            var moduleRule = CreateRule();
            ReadModuleChecker readAssetChecker = new(moduleRule);
            readAssetChecker.CheckModelByRule();
        }

        private static List<RequireRule> CreateArtRules()
        {
            List<RequireRule> requireRules = new()
            {
                new RequireRule("analysis",
                    new HashSet<string> { ".png" },
                    new HashSet<string> { @"^analysis_\d{1}_\d{1}" }),

                new RequireRule("config",
                   new HashSet<string> { ".json" },
                   new HashSet<string> { @"^BaseConfig$" }
                   ),

                new RequireRule("node",
                   new HashSet<string> { ".png", ".asset", ".prefab" },
                   null,
                   new HashSet<string> { @"^game\d{1}" }
                   ),

                new RequireRule("sound",
                   new HashSet<string> { ".ogg" },
                   new HashSet<string> { @"^analyse\d$", @"^answer_\d_\d$", @"^question\d$", @"^s_right_\d$", @"^s_wrong_\d$" }
                   ),

                new RequireRule("",
                   null, null,
                   new HashSet<string> { "analysis", "config", "node", "sound" }
                   )
            };
            return requireRules;
        }

        private static List<RequireRule> CreateSrcRules()
        {
            List<RequireRule> requireRules = new()
            {
                  new RequireRule("",null,null,null,CheckSrcRoot)
            };
            return requireRules;
        }

        private static void CheckSrcRoot(string path, ReadModuleChecker checker)
        {
            List<string> mustHaveFiles = new()
            {
                Path.Combine(path, string.Format("Exercise{0}resLink.asset", checker.CurId)),
                Path.Combine(path, string.Format("Exercise{0}resLink.lua", checker.CurId)),
                Path.Combine(path, string.Format("Exercise{0}Config.lua", checker.CurId))
            };
            checker.CheckFilesExists(mustHaveFiles);
        }

        public static ModuleRule CreateRule()
        {
            var moduleRule = new ModuleRule("art/game/gushi/exercise", @"^exercise\d{4}$","gamesrc/poetry/exercise")
            {
                ArtRequireList = CreateArtRules(),
                SrcRequireList = CreateSrcRules()
            };
            return moduleRule;
        }
    }
}