//
//  SkillsExtensions.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.
using NosSmooth.Game.Data.Characters;
using Remora.Results;
namespace NosSmooth.Game.Extensions;
/// 
/// Contains extension methods for .
/// 
public static class SkillsExtensions
{
    /// 
    /// Tries to get the skill of the specified vnum.
    /// 
    /// The skills of the player.
    /// The cast id to search for.
    /// The skill, if found.
    public static Result TryGetSkillByCastId(this Skills skills, short castId)
    {
        if (skills.PrimarySkill.Info?.CastId == castId)
        {
            return skills.PrimarySkill;
        }
        if (skills.SecondarySkill.Info?.CastId == castId)
        {
            return skills.SecondarySkill;
        }
        foreach (Skill skill in skills.OtherSkills)
        {
            if (skill.Info?.CastId == castId)
            {
                return skill;
            }
        }
        return new NotFoundError();
    }
    /// 
    /// Tries to get the skill of the specified vnum.
    /// 
    /// The skills of the player.
    /// The vnum to search for.
    /// The skill, if found.
    public static Result TryGetSkillByVNum(this Skills skills, long skillVNum)
    {
        if (skills.PrimarySkill.SkillVNum == skillVNum)
        {
            return skills.PrimarySkill;
        }
        if (skills.SecondarySkill.SkillVNum == skillVNum)
        {
            return skills.SecondarySkill;
        }
        foreach (Skill skill in skills.OtherSkills)
        {
            if (skill.SkillVNum == skillVNum)
            {
                return skill;
            }
        }
        return new NotFoundError();
    }
}