using UnityEngine;

namespace InterfaceOff
{
    [System.Serializable]
    public struct Advert
    {
        [field: SerializeField] public string Name { get; private set; }
        [field: SerializeField] public Sprite Image { get; private set; }
    }

    [CreateAssetMenu(fileName = "Advert Registry", menuName = "Custom/Create Advert Registry")]
    public class AdvertRegistry : ScriptableObject
    {
        [field: SerializeField] public Advert[] m_Adverts;
        private static AdvertRegistry Instance;

        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
        private static void LoadRegistry() => Instance = Resources.Load<AdvertRegistry>("AdvertRegistry");

        public static Advert GetRandomAdvert()
        {
            int index = Random.Range(0, Instance.m_Adverts.Length);
            return Instance.m_Adverts[index];
        }
    }
}