using DoomDeathmatch.Component.Physics.Collision;
using Engine.Scene;
using Engine.Scene.Component.BuiltIn;
using OpenTK.Mathematics;

namespace DoomDeathmatch;

public static class GameObjectUtil
{
  public static GameObject CreateGameObject(Engine.Scene.Scene parScene)
  {
    var gameObject = new GameObject();

    parScene.Add(gameObject);

    return gameObject;
  }

  public static GameObject CreateGameObject(Engine.Scene.Scene parScene, Transform parTransform)
  {
    var gameObject = new GameObject(parTransform);

    parScene.Add(gameObject);

    return gameObject;
  }

  public static GameObject CreateGameObject(Engine.Scene.Scene parScene,
    List<Engine.Scene.Component.Component> parComponents)
  {
    var gameObject = new GameObject();
    foreach (var component in parComponents)
    {
      gameObject.AddComponent(component);
    }

    parScene.Add(gameObject);

    return gameObject;
  }

  public static GameObject CreateGameObject(Engine.Scene.Scene parScene, Transform parTransform,
    List<Engine.Scene.Component.Component> parComponents)
  {
    var gameObject = new GameObject(parTransform);
    foreach (var component in parComponents)
    {
      gameObject.AddComponent(component);
    }

    parScene.Add(gameObject);

    return gameObject;
  }

  public static GameObject CreateColliderForceField(Engine.Scene.Scene parScene, AABBColliderComponent parCollider)
  {
    var offset = parCollider.Offset;
    parCollider.Offset = Vector3.Zero;

    var forceFieldObject = CreateGameObject(parScene,
      new Transform { Translation = offset, Size = parCollider.Collider.Size },
      [
        parCollider,
        new ColliderForceFieldComponent()
      ]
    );

    return forceFieldObject;
  }
}