namespace Managing.Domain.Evm;


public static class HolderExtensions
{
    public static void AddNft(this Holder holder, Nft nft)
    {
        if (holder.Nfts.FirstOrDefault(n => n.TokenId == nft.TokenId) == null)
        {
            holder.Nfts.Add(nft);
        }
    }

    public static List<Holder> GetYields(this List<Holder> holders, decimal yieldAmount)
    {
        var nftHeldCount = 0;
        foreach (var holder in holders)
        {
            nftHeldCount += holder.Nfts.Count;
        }

        var yieldPerNft = yieldAmount / nftHeldCount;

        foreach (var holder in holders)
        {
            holder.Yield = holder.Nfts.Count * yieldPerNft;
        }

        return holders;
    }
}
