using System.Collections.Generic;
using UnityEngine;
using YachtDice.Modifiers.Core;
using YachtDice.Shop;

namespace YachtDice.Modifiers.Definition
{
    [CreateAssetMenu(fileName = "NewModifier", menuName = "YachtDice/Modifiers/Definition")]
    public class ModifierDefinition : ScriptableObject, IShopItem
    {
        [field: Header("Identity")]
        [field: SerializeField] public string Id { get; private set; }
        [field: SerializeField] public string DisplayName { get; private set; }
        [field: SerializeField, TextArea] public string Description { get; private set; }
        [field: SerializeField] public Sprite Icon { get; private set; }
        [field: SerializeField] public ModifierRarity Rarity { get; private set; }

        [field: Header("Economy")]
        [field: SerializeField] public int ShopPrice { get; private set; }
        [field: SerializeField] public int SellPrice { get; private set; }

        [field: Header("Durability")]
        [field: SerializeField] public bool HasLimitedUses { get; private set; }
        [field: SerializeField] public int MaxUses { get; private set; }
        [field: SerializeField] public int MaxStacks { get; private set; } = 1;

        [Header("Behaviors")]
        [SerializeField] private List<ModifierBehavior> behaviors = new();

        public bool IsRepurchasable => HasLimitedUses;
        public IReadOnlyList<ModifierBehavior> Behaviors => behaviors;

#if UNITY_EDITOR
        public static ModifierDefinition CreateForTest(
            string id,
            List<ModifierBehavior> behaviors,
            bool hasLimitedUses = false,
            int maxUses = 0,
            int shopPrice = 100,
            int sellPrice = 50,
            ModifierRarity rarity = ModifierRarity.Common)
        {
            var so = CreateInstance<ModifierDefinition>();
            so.Id = id;
            so.DisplayName = id;
            so.Description = id;
            so.Rarity = rarity;
            so.ShopPrice = shopPrice;
            so.SellPrice = sellPrice;
            so.HasLimitedUses = hasLimitedUses;
            so.MaxUses = maxUses;
            so.behaviors = behaviors ?? new List<ModifierBehavior>();
            return so;
        }
#endif
    }
}
