using UnityEngine;

namespace MyGame.Scripts
{
    public class ShopCustomizeCoinManager : SingletonMonoBehaviour<ShopCustomizeCoinManager>
    {
        [SerializeField] private TextWithCountUpInt coinCountText;
        [SerializeField] private float coinUpDuration = 0.5f;

        private int ownCoin;
        public int OwnCoin => ownCoin;
        private string coinTextFormat = "{0}";
        void Awake(){
            if(CheckInstance()) return ;
        }
        
        public void ChangeCoin(int count)
        {
            ownCoin = count;
            coinCountText.ChangeValue(coinTextFormat, ownCoin);
        }

        public void AddCoin(int count)
        {
            ownCoin += count;
            SoundManager.Instance.PlaySE("se_coin_get");
            coinCountText.CountUpAnimation(coinTextFormat, ownCoin, coinUpDuration);
        }
        
        public void SubCoin(int coin){
            ownCoin -= coin;
            if(coinCountText.gameObject.activeInHierarchy){
                coinCountText.CountUpAnimation(coinTextFormat, ownCoin, coinUpDuration);
            }else{
                coinCountText.ChangeValue(coinTextFormat, ownCoin);
            }
        }

    }
}