using UnityEngine;

public abstract class Building : MonoBehaviour
{ 
    public BuildingData BuildingData;
    [SerializeField] protected bool operational = false;
    private BuildingBuilder buildingBuilder;
    [SerializeField] private BuildingBuilder buildingBuilderPrefab;

    public virtual void Demolish()
    {
        if (buildingBuilder != null)
            buildingBuilder.PeopleCardHoldArea.DropCards();
        Destroy(gameObject);
    }

    public virtual void Initiate(BuildingData buildingData)
    {
        if (BuildingData == null)
        {
            BuildingData = buildingData;
            buildingBuilder = Instantiate(buildingBuilderPrefab, transform.position, Quaternion.identity, transform);
            buildingBuilder.Initiate(this);
        }
        else BuildingData = buildingData;
    }
    
    public virtual void Build()
    {
        MapManager.Instance.BuildingBuilt(transform.position, BuildingData);
        operational = true;
    }

}
