namespace Engine.Scene.Component;

public abstract class Component : IUpdate, IRender
{
  public Guid Id { get; } = Guid.NewGuid();

  public GameObject GameObject { get; internal set; }

  public virtual void Awake()
  {
  }

  public virtual void Start()
  {
  }

  public virtual void PreUpdate()
  {
  }

  public virtual void Update(double parDeltaTime)
  {
  }

  public virtual void Render()
  {
  }

  public virtual void Destroy()
  {
  }

  public virtual void Enable()
  {
  }

  public virtual void Disable()
  {
  }
}

public static class ComponentTypeExtensions
{
  internal static Type GetComponentBaseType(this Type parType)
  {
    var baseType = parType.BaseType;
    if (baseType == null || baseType == typeof(Component))
    {
      return parType;
    }

    while (baseType.BaseType != null && baseType.BaseType != typeof(Component))
    {
      baseType = baseType.BaseType;
    }

    return baseType;
  }
}