using System.Collections.Generic;
using UnityEngine;

namespace YachtDice.Dice
{
    [CreateAssetMenu(fileName = "DiceCatalog", menuName = "YachtDice/Dice/Catalog")]
    public class DiceCatalog : ScriptableObject
    {
        [SerializeField] private List<DieDefinitionSO> dice = new();

        public IReadOnlyList<DieDefinitionSO> All => dice;

        public DieDefinitionSO FindById(string id)
        {
            for (int i = 0; i < dice.Count; i++)
            {
                if (dice[i] != null && dice[i].Id == id)
                    return dice[i];
            }
            return null;
        }

#if UNITY_EDITOR
        public static DiceCatalog CreateForTest(List<DieDefinitionSO> defs)
        {
            var catalog = CreateInstance<DiceCatalog>();
            catalog.dice = defs ?? new List<DieDefinitionSO>();
            return catalog;
        }
#endif
    }
}
