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

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

        private static List<RequireRule> CreateArtRules()
        {
            List<RequireRule> requireRules = new()
            {
                new RequireRule("video",
                new HashSet<string> { ".mp4", ".txt" },
                new HashSet<string> { @"^video_poetry_sing_\d{4}(_srt)*" },null,
                CheckVideo),

                new RequireRule("",
                       null, null,
                       new HashSet<string> { "video" }
                   )
            };
            return requireRules;
        }

        private static void CheckVideo(string path, ReadModuleChecker checker)
        {
            List<string> mustHaveFiles = new()
            {
                Path.Combine(path, string.Format("video_poetry_sing_{0}.mp4", checker.CurId)),
                Path.Combine(path, string.Format("video_poetry_sing_{0}_srt.txt", checker.CurId))
            };
            checker.CheckFilesExists(mustHaveFiles);     
        }

        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("sing{0}reslink.lua", checker.CurId)),
                Path.Combine(path, string.Format("sing{0}resLink.asset", checker.CurId)),
            };
            checker.CheckFilesExists(mustHaveFiles);
        }

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