public class Research
{
    public ResearchData data;
    public double elapsedResearchTime = 0;
    public bool paidResources = false;
    public ResearchState state;

    public Research(ResearchData data)
    {
        this.data = data;
        state = ResearchState.UNDEFINED;
    }

    public ResearchResult Execute(double delta)
    {
        if (!paidResources)
        {
            foreach (Ingredient ingredient in data.Inputs)
            {
                GameData.inventory.RemoveItem(ingredient.Item, ingredient.Amount);
            }
            paidResources = true;
        }

        elapsedResearchTime += delta;
        if (elapsedResearchTime >= data.CraftTime)
        {
            Complete();
            return ResearchResult.FINISHED;
        }
        return ResearchResult.RESEARCHING;
    }

    public void Complete()
    {
        if (state == ResearchState.RESEARCHED) return;

        state = ResearchState.RESEARCHED;
        GameData.robotStats.Apply(data.Effects);
    }

    public static string GetReadableName(string input)
    {
        string noUnderscore = input.Replace("_", " ").ToLower();
        return char.ToUpper(noUnderscore[0]) + noUnderscore.Substring(1);
    }
}
