using GameDev.CoreSystems;
using UnityEngine;

namespace AsteroidGame.Entities
{
    public class PowerBase : MonoBehaviour, IPowerSystem
    {
        [Header("State")]
        [SerializeField] protected bool _isGenerator = true;
        [SerializeField] protected bool _isConsumer = true;
        [SerializeField] protected int _maxPower;
        [SerializeField] protected int _currentPower;

        [SerializeField] private SoPowerSystemRuntimeSet _powerBaseSet;

        public void Initialize(SoPowerConfig config)
        {
            _isGenerator = config.isGenerator;
            _isConsumer = config.isConsumer;
            _maxPower = config.maxPower;
            _powerBaseSet = config._runtimeSet;
            _powerBaseSet.Add(this);
        }

        private void OnDisable()
        {
            _powerBaseSet.Remove(this);
        }

        #region Setters

        public void SetMaxPower(int newValue) => _maxPower = newValue;

        #endregion

        #region Getters

        public bool IsGenerator => _isGenerator;

        public bool IsConsumer => _isConsumer;

        public int GetMaxPower() => _maxPower;

        public int GetCurrentPower() => _currentPower;

        public float GetPowerFactor() => (float)_currentPower / _maxPower;

        #endregion
    }
}