using System;
using System.Collections.Generic;
using UnityEngine;

namespace FL.Battle
{
    /// <summary>
    /// 目标查找方式
    /// </summary>
    public enum ETargetFindType
    {
        /// <summary>
        /// 找最近的
        /// 过滤移动和受保护的
        /// </summary>
        Nearest = 0,
        /// <summary>
        /// 找最近的
        /// 只过滤死亡，其他状态都可选
        /// </summary>
        NearestAlive,
        /// <summary>
        /// 找范围内的
        /// 过滤移动和受保护的
        /// </summary>
        InRange,
        /// <summary>
        /// 找范围内的
        /// 只过滤死亡，其他状态都可选
        /// </summary>
        InRangeAlive,
    }

    public struct FinderInfo
    {
        public long uid;
        /// <summary>
        /// 世界坐标
        /// </summary>
        public Vector3 position;
        /// <summary>
        /// 半径
        /// </summary>
        public float radius;
    }
    /// <summary>
    /// 目标选择器
    /// </summary>
    public interface ITargetSelector
    {
        ITarget GetTarget(long entityId);
        ITarget GetPlayer();
        /// <summary>
        /// 同步查找目标
        /// </summary>
        /// <param name="finder"></param>
        /// <param name="targetType"></param>
        /// <param name="findType"></param>
        /// <param name="customFilter">自定义过滤器，不能选择时返回true</param>
        /// <returns></returns>
        ITarget FindSync(ITarget finder, EEntityType targetType, ETargetFindType findType = ETargetFindType.Nearest, Func<ITarget, bool> customFilter = null);
        /// <summary>
        /// 同步查找目标
        /// </summary>
        /// <param name="finder"></param>
        /// <param name="targetType"></param>
        /// <param name="findType"></param>
        /// <param name="customFilter">自定义过滤器，不能选择时返回true</param>
        /// <returns></returns>
        ITarget FindSync(FinderInfo finder, EEntityType targetType, ETargetFindType findType = ETargetFindType.Nearest, Func<ITarget, bool> customFilter = null);
        /// <summary>
        /// 查找范围内所有目标
        /// ETargetFindType.Nearest和NearestAlive无效
        /// </summary>
        /// <param name="finder"></param>
        /// <param name="targetType"></param>
        /// <param name="findType"></param>
        /// <param name="customFilter"></param>
        /// <param name="targets"></param>
        /// <returns></returns>
        bool FindTargets(FinderInfo finder, EEntityType targetType, ETargetFindType findType, Func<ITarget, bool> customFilter, ref List<ITarget> targets);
        /// <summary>
        /// 查找范围内所有目标
        /// ETargetFindType.Nearest和NearestAlive无效
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="targetType"></param>
        /// <param name="findType"></param>
        /// <param name="customFilter"></param>
        /// <param name="targets"></param>
        /// <returns></returns>
        bool FindTargets(Rect rect, EEntityType targetType, ETargetFindType findType, Func<ITarget, bool> customFilter, ref List<ITarget> targets);

        /// <summary>
        /// 异步查找目标
        /// </summary>
        /// <param name="finder"></param>
        /// <param name="targetType"></param>
        /// <param name="findType"></param>
        /// <param name="onSelected"></param>
        void FindAsync(ITarget finder, EEntityType targetType, ETargetFindType findType, Action<ITarget> onSelected);
    }
}
