using PkmnLib.Dynamic.Libraries.DataLoaders.Models;
using PkmnLib.Static.Moves;
using PkmnLib.Static.Utils;

namespace PkmnLib.Dynamic.Libraries.DataLoaders;

internal static class CommonDataLoaderHelper
{
    internal static ISecondaryEffect? ParseEffect(this SerializedMoveEffect? effect)
    {
        if (effect == null)
            return null;
        var name = effect.Name;
        var chance = effect.Chance ?? -1;
        var parameters = effect.Parameters?.ToDictionary(x => (StringKey)x.Key, x => x.Value.ToParameter()) ??
                         new Dictionary<StringKey, object?>();
        return new SecondaryEffectImpl(chance, name, parameters);
    }
}