using System;
using UnityEngine;
using Random = UnityEngine.Random;
using RetroDev.Random;
using UnityEngine.UI;

public class UpgradeManager : MonoBehaviour
{
    public static UpgradeManager Instance;

    [Serializable]
    public class UpgradeOption
    {
        public string name;
        public UpgradeType type;
        public Sprite icon;
        public string description;
        public int minCost;
        public int maxCost;
        private int cost;
        public float minValue;
        public float maxValue;
        private float value;

        // Property to access the private cost variable
        public int Cost
        {
            get { return cost; }
            set { cost = value; }
        }

        // Property to access the private value variable
        public float Value
        {
            get { return value; }
            set { this.value = value; }
        }
    }

    // Enums for the upgrade type
    public enum UpgradeType
    {
        MovementSpeed,
        FireRate,
        BulletDamage,
        ShieldCapacity,
        RotationSpeed,
        DashSpeed   
        // More upgrade types can be added if required
    }

    [Header("Upgrade Options")]
    public UpgradeOption[] potentialUpgrades;

    [Header("Upgrade Configuration")]
    public int numberOfUpgradeOptions = 2;

    private void Awake()
    {
        Instance = this;
    }


    private void Start()
    {
        // Ensure the number of upgrade options is not greater than the number of potential upgrades
        numberOfUpgradeOptions = Mathf.Min(numberOfUpgradeOptions, potentialUpgrades.Length);
    }

    // A function to generate a random upgrade
    public UpgradeOption GenerateRandomUpgrade()
    {
        // Choose a random index within the range of potential upgrades
        int randomIndex = Random.Range(0, potentialUpgrades.Length);

        // Get the selected upgrade option
        UpgradeOption option = potentialUpgrades[randomIndex];

        // Set the cost and value based on the predefined ranges for the upgrade type
        option.Cost = RandomUtil.RandomNumber(option.minCost, option.maxCost);
        option.Value = RandomUtil.RandomFloat(option.minValue, option.maxValue);

        // Return the randomly chosen and upgraded upgrade option
        return option;
    }
}
