using System;
using System.Collections.Generic;
namespace Tool.ReadChecker
{
    public class ModuleRule
    {
        public string artRootPath;
        public string srcRootPath;
        public readonly string artNamePattern;
        public readonly string srcNamePattern;
        private List<RequireRule> artRequireList;
        private List<RequireRule> srcRequireList;

        private bool isArtSet = false;
        private bool isSrcSet = false;
        public List<RequireRule> ArtRequireList {
            get{
                return artRequireList;
            }
            set
            {
                if (isArtSet)
                {
                    throw new InvalidOperationException("The ArtRequireList can only be set once.");
                }
                artRequireList = value;
                isArtSet = true;
            }
        }
        public List<RequireRule> SrcRequireList {
            get
            {
                return srcRequireList;
            }
            set
            {
                if (isSrcSet)
                {
                    throw new InvalidOperationException("The SrcRequireList can only be set once.");
                }
                srcRequireList = value;
                isSrcSet = true;
            }
        }
        public ModuleRule(string artPath, string artNamePattern, string srcPath = null,string srcNamePattern = null)
        {
            artRootPath = artPath;
            srcRootPath = srcPath;
            this.artNamePattern = artNamePattern;
            this.srcNamePattern = srcNamePattern;
        }
    }
    public class RequireRule
    {
        public string path;
        public readonly HashSet<string> allowedExtensionSet;
        public readonly HashSet<string> allowedFileNamePatternSet;
        public readonly HashSet<string> allowedFolderNamePatternSet;
        public Action<string, ReadModuleChecker> extraCheck;

        public bool Strict { get; set; } = true;
        public RequireRule(string path, HashSet<string> extensionSet = null, HashSet<string> allowedNamePatternSet = null, HashSet<string> allowedFolderPatternSet = null, Action<string, ReadModuleChecker> extraCheck = null)
        {
            this.path = path;

            allowedExtensionSet = extensionSet;
            allowedFileNamePatternSet = allowedNamePatternSet;
            allowedFolderNamePatternSet = allowedFolderPatternSet;
            this.extraCheck = extraCheck;
        }
    }
}