﻿using System;
using Assets.Standard_Assets.Scripts.Enums;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(Button))]
public class TowerSelection : MonoBehaviour
{
    public TowerTypeSpecificEnum towerType;

    private Button _button;
    private Economy _economy;
    private Markermooving _marker;
    private float _timer = 0;
    void Start()
    {
        _button = gameObject.GetComponent<Button>();
        _economy = GameObject.FindGameObjectWithTag("GameController").GetComponent<Economy>();
        _marker = (Markermooving) FindObjectOfType(typeof(Markermooving));

        _button.onClick.AddListener(OnButtonClick);
    }

    private void OnButtonClick()
    {
        _marker.ShowInformationAboutTowerToPlayer(towerType);
    }

    void Update()
    {
        // update every second usability of button
        if (_timer < 0)
        {
            _button.interactable = _economy.PriceForTower(towerType) < _economy.playermoney;
            _timer = 1;
        }
        _timer -= Time.deltaTime;
    }
}
