using UnityEngine;

public class ObjectPlaceholder : UnitPlaceholder
{
    public GameObject Prefab { get; set; }
    public override void Place()
    {
        base.Place();
        Prefab.Create(transform.position, parent : LevelManager.Instance.LevelTransform);
    }
    public override bool CanBePlacedHere()
    {
        var objsOnPosition = LevelManager.Instance.GetAll<ILevelObject>(obj => obj.Position.IsContainedIn(transform.position));
        var positionIsCollidable = objsOnPosition.Exists(obj => obj.IsCollidable);

        var defaultUnitCost = GlobalConfig.Instance.Current.populationCostPerUnit;
        return !positionIsCollidable 
            && LevelBoundCache.Contains(transform.position)
            && ResourceManager.Instance.EnoughFor(Rock, Wood, Food)
            && (Prefab.GetComponent<Building>()
            || ResourceManager.Instance.EnoughPopulationFor(defaultUnitCost));
    }
}