using UnityEngine;
using mgaia.Utils;
using mgaia.Utils.LayerSystem;

public class HudView : IInputReceivable
{
    [SerializeField]
    private tk2dTextMesh _wealthyQuantityText;

    [SerializeField]
    private tk2dTextMesh _popularityQuantityText;

    [SerializeField]
    private tk2dTextMesh _warpowerQuantityText;

    private AttributeManager mAttributeManager;

    public override void OnDataPackReceived(object dataPack)
    {
        Assert.AssertTrue(dataPack is AttributeManager, "O dataPack precisa ser AttributeManager!");

        mAttributeManager = (AttributeManager)dataPack;
        mAttributeManager.OnIndicatorChanged += OnIndicatorChanged;
    }

    private void OnIndicatorChanged(Indicators indicator, float value)
    {
        tk2dTextMesh targetTextMesh = default(tk2dTextMesh);

        switch (indicator)
        {
            case Indicators.Popularity:
                targetTextMesh = _popularityQuantityText;
                break;
            case Indicators.Warpower:
                targetTextMesh = _warpowerQuantityText;
                break;
            case Indicators.Wealthy:
                targetTextMesh = _wealthyQuantityText;
                break;
        }

        Assert.AssertTrue(targetTextMesh != null, "Nenhuma textMesh foi encontrada para o atributo " + indicator);

        targetTextMesh.text = string.Format("{0}%", Mathf.RoundToInt(value * 100)); 
    }

    private void OnDestroy()
    {
        mAttributeManager.OnIndicatorChanged -= OnIndicatorChanged;
    }
}