﻿using System;
using JLGames.RocketDriver.Games.RpgMaterial.Material;

namespace JLGames.RocketDriver.Games.RpgMaterial.Material
{
    public interface IMaterialSet
    {
        /// <summary>
        /// Number of material items
        /// 材料条目数量
        /// </summary>
        int MaterialSize { get; }

        /// <summary>
        /// Check if material is exist
        /// 判断材料是否存在
        /// </summary>
        /// <param name="mId"></param>
        /// <returns></returns>
        bool ExistMaterial(int mId);

        /// <summary>
        /// Get number of material items by match function
        /// 按要求计算材料条目数量
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        int GetSizeAs<TMAs>(Predicate<TMAs> match) where TMAs : class, IMaterial;

        /// <summary>
        /// Get the material definition
        /// 取材料定义
        /// If it is defined as the specified data type, convert the type to return, otherwise return null
        /// 如果定义为指定数据类型，则转类型返回，否则返回null
        /// </summary>
        /// <param name="mId"></param>
        /// <typeparam name="TMAs"></typeparam>
        /// <returns></returns>
        TMAs GetMaterialAs<TMAs>(int mId) where TMAs : class, IMaterial;

        /// <summary>
        /// Iterate over each material
        /// 遍历全部材料
        /// </summary>
        /// <param name="each"></param>
        void ForeachMaterialAs<TMAs>(Action<TMAs> each) where TMAs : class, IMaterial;
    }

    public interface IMaterialSet<TM, TCfg> : IMaterialSet where TM : IMaterial<TCfg>
    {
        /// <summary>
        /// Get material size by match function
        /// 按要求计算符合条件的材料数量
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        int GetSize(Predicate<TM> match);

        /// <summary>
        /// Get the material definition
        /// 取材料定义
        /// </summary>
        /// <param name="mId"></param>
        /// <returns></returns>
        TM GetMaterial(int mId);

        /// <summary>
        /// Get all material definitions
        /// 取全部的材料定义
        /// </summary>
        /// <returns></returns>
        TM[] GetMaterials();

        /// <summary>
        /// Get some material definitions by match function
        /// 取部分材料定义
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        TM[] GetMaterials(Predicate<TM> match);

        /// <summary>
        /// Iterate over each material
        /// 遍历全部材料
        /// </summary>
        /// <param name="each"></param>
        void ForeachMaterial(Action<TM> each);
    }
}