using ScenarioFlow;
using ScenarioFlow.Scripts.SFText;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace HowToWriteSFText
{
    public class SpriteProvider : MonoBehaviour, IReflectable
    {
        [SerializeField]
        private Sprite[] sprites;

        private Dictionary<string, Sprite> spriteDictionary;

        private void Awake()
        {
            spriteDictionary = sprites.ToDictionary(x => x.name);
        }

        [DecoderMethod]
        [Category("Resource")]
        [Description("Decoder for 'Sprite'.")]
        [Description("Sprites need to be registered so that they will be available.")]
        public Sprite GetSprite(string name)
        {
            if (spriteDictionary.TryGetValue(name, out var sprite))
            {
                return sprite;
            }
            else
            {
                throw new ArgumentException($"Sprite '{name}' does not exist.");
            }
        }
    }
}