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

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

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

        private static List<RequireRule> CreateArtRules()
        {
            List<RequireRule> requireRules = new()
            {
                new RequireRule("game",
                 new HashSet<string> { ".asset" }),

                new RequireRule("sound",
                 new HashSet<string> { ".ogg" },
                 new HashSet<string> { @"^\d{4}_V01" },null,
                 CheckSound),

                new RequireRule("spine",
                 new HashSet<string> { ".png", ".json", ".txt", ".asset", ".mat" }),

                new RequireRule("video",
                 new HashSet<string> { ".mp4", ".txt" },
                 new HashSet<string> { @"^video_poetry_through_\d{4}(_srt)*" },null,
                 CheckVideo),

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

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

        private static void CheckSound(string path, ReadModuleChecker checker)
        {
            string mustHaveFile = Path.Combine(path, string.Format("{0}_V01.ogg", checker.CurId));
            checker.CheckFileExists(mustHaveFile);
        }

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