using Godot;

namespace Game;

[GlobalClass]
public partial class Ceo : Resource
{
    private float _competence = 50;
    private float _energy = 100;
    private float _insanity;
    private float _maxEnergy = 100;
    private string _name = "";

    [Export]
    public string Name
    {
        get => _name;
        set
        {
            _name = value;
            EmitCeoStatusChanged();
        }
    }

    [Export]
    public float Energy
    {
        get => _energy;
        set
        {
            _energy = Mathf.Clamp(value, 0, MaxEnergy);
            EmitCeoStatusChanged();
        }
    }

    [Export]
    public float MaxEnergy
    {
        get => _maxEnergy;
        set
        {
            _maxEnergy = Mathf.Max(value, 0);
            _energy = Mathf.Min(_energy, _maxEnergy);
            EmitCeoStatusChanged();
        }
    }

    [Export]
    public float Insanity
    {
        get => _insanity;
        set
        {
            _insanity = value;
            EmitCeoStatusChanged();
        }
    }

    [Export]
    public float Competence
    {
        get => _competence;
        set
        {
            _competence = value;
            EmitCeoStatusChanged();
        }
    }

    private void EmitCeoStatusChanged()
    {
        EventBus.CeoChanged.Invoke(ToCeoStats());
    }

    public CeoStats ToCeoStats()
    {
        return new CeoStats(Name, Energy, MaxEnergy, Insanity, Competence);
    }

    public record CeoStats(
        string Name,
        float Energy,
        float MaxEnergy,
        float Insanity,
        float Competence
    );
}
