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

namespace Tool.ReadChecker
{
    public class MonthChecker : ScriptableObject
    {
        [MenuItem("Tool/ReadChecker/CheckMonth")]
        public static void CheckeMonthModel()
        {
            var moduleRule = CreateRule();
            ReadModuleChecker readAssetChecker = new(moduleRule);
            readAssetChecker.CheckModelByRule();
        }

        public static ModuleRule CreateRule()
        {
            var moduleRule = new ModuleRule("art/game/monthly",  @"^monthly\d{4}$" );
            List<RequireRule> requireRules = new()
            {
                new RequireRule("reslink",
                     new HashSet<string> { ".asset",".lua" },
                     new HashSet<string> { @"^\d{4}reslink$"},null,
                     CheckResLink
                     ),

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

                new RequireRule("",
                    null, null,
                    new HashSet<string> { "video", "reslink" }
                )
            };
            moduleRule.ArtRequireList = requireRules;
            return moduleRule;
        }

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

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