using Godot;

namespace Game;

[GlobalClass]
public partial class Company : Resource
{
    private float _averageSalary = 100;
    private float _hype;
    private float _money = 1_000;
    private float _workers = 1;

    [Export]
    public float Hype
    {
        get => _hype;
        set
        {
            _hype = value;
            EmitCompanyStatusChanged();
        }
    }

    [Export]
    public float Money
    {
        get => _money;
        set
        {
            _money = value;
            EmitCompanyStatusChanged();
        }
    }

    [Export]
    public float Workers
    {
        get => _workers;
        set
        {
            _workers = value;
            EmitCompanyStatusChanged();
        }
    }

    [Export]
    public float AverageSalary
    {
        get => _averageSalary;
        set
        {
            _averageSalary = value;
            EmitCompanyStatusChanged();
        }
    }

    /// <summary>
    ///     Cost per Quarter
    /// </summary>
    public float Cost => Workers * AverageSalary;

    /// <summary>
    ///     Runway in Quarters
    /// </summary>
    public int Runway => Mathf.FloorToInt(Money / Cost);

    private void EmitCompanyStatusChanged()
    {
        EventBus.CompanyChanged.Invoke(ToCompanyStats());
    }

    public CompanyStats ToCompanyStats()
    {
        return new CompanyStats(Hype, Money, Workers, Runway);
    }

    public record CompanyStats(float Hype, float Money, float Workers, int Runway);
}
