using UnityEngine;
using System.Collections.Generic;
using static Enum;

public class Harvester : Ally
{
    [SerializeField] [Tooltip("helps choose the right skin for the harvester depending on resource")]
    private List<HarvesterResourcePair> _harvesterResourcePairs;
    protected ResourceNodeType ResourceNodeType => _resourceNodeType;

    public override Vector2 RangeMultiplier { get; }

    public override float HpMultiplier { get; }

    public override float SpeedMultiplier { get; }

    public override float DamageMultiplier { get; }

    public override float AttackSpeedMultiplier { get; }

    [SerializeField]
    private ResourceNodeType _resourceNodeType;

    [SerializeField]
    private float _gatherRate = 1f;
    public float GatherRate => _gatherRate;

    public override sealed void Start()
    {
        base.Start();

        ChooseSkinForHarvester();
    }

    /// <summary>
    /// changes the harvester's appearance depending on the resource they're harvesting
    /// </summary>
    private void ChooseSkinForHarvester()
    {
        //get the tile we're on
        var tile = LevelManager.Instance.Get<ResourceTile>(t => t.Position == Position);
        if (tile == default) return;

        //if we already have the right harvester for the resource, no need to change
        var resourceChoice = tile.ResourceNodeType;
        if (resourceChoice == this.ResourceNodeType) return;

        //get the right pair for the resource we're on
        var harvResPair = _harvesterResourcePairs.Find(hrp => hrp.Resource == resourceChoice);
        if (harvResPair == null) return;

        //exchange harvesters
        var newHarvester = Instantiate(harvResPair.HarvesterPrefab, transform.position, Quaternion.identity);
        newHarvester.transform.SetParent(transform.parent);
        Destroy(gameObject);
    }
}