CardCollectionView.cs

Static helper for the card collection view. Returns either owned cards or the catalog variants, resolves a card by key and copy id, lists copies of a key ordered by id, and computes a card's copy number.

using System;
using System.Collections.Generic;
using System.Linq;

namespace Socer;

// Owned cards stay actual distinct instances; a catalog identity is not a copy.
public static class CardCollectionView
{
    public static IEnumerable<PlayerCard> Cards(ClubCareer career,bool owned)=>owned?career.Cards:PlayerCatalog.CardVariants;
    public static PlayerCard Inspect(ClubCareer career,string key,int copyId)=>copyId>=0
        ?career.Cards.FirstOrDefault(c=>c.Id==copyId && c.CardKey==key):PlayerCatalog.FindVariant(key);
    public static PlayerCard[] Copies(ClubCareer career,string key)=>career.Cards.Where(c=>c.CardKey==key).OrderBy(c=>c.Id).ToArray();
    public static int CopyNumber(ClubCareer career,PlayerCard card)=>Array.FindIndex(Copies(career,card.CardKey),c=>c.Id==card.Id)+1;
}