using DoomDeathmatch.Component.MVC;
using DoomDeathmatch.Component.MVC.Health;
using DoomDeathmatch.Component.MVC.Weapon;
using DoomDeathmatch.Component.Physics;
using DoomDeathmatch.Component.Physics.Collision;
using DoomDeathmatch.Component.Util;
using DoomDeathmatch.Script.Collision;
using Engine.Scene;
using OpenTK.Mathematics;

namespace DoomDeathmatch.Scene.Play.Prefab;

public static class PlayerPrefab
{
  public static GameObject Create(Engine.Scene.Scene parScene, WeaponView parWeaponView, HealthView parHealthView)
  {
    var (perspectiveCameraObject, perspectiveCamera) = UiUtil.CreatePerspectiveCamera(parScene);
    perspectiveCameraObject.Transform.Translation.Z = 2;
    var playerObject = GameObjectUtil.CreateGameObject(parScene, [
      new PlayerMovementComponent(),

      new MovementController { Speed = 10f },
      new RigidbodyComponent(),
      new DragComponent { Drag = 10f, Multiplier = new Vector3(1, 1, 0) },

      new AABBColliderComponent
      {
        Collider = new AABBCollider { Size = new Vector3(1, 1, 2) },
        Offset = new Vector3(0, 0f, 1f),
        ColliderGroups = { "player" },
        ExcludeColliderCollideGroups = { "player" }
      },

      new PlayerController(perspectiveCamera),

      new WeaponController(),
      parWeaponView,

      new HealthController(),
      parHealthView,
    ]);

    parScene.AddChild(playerObject, perspectiveCameraObject);

    return playerObject;
  }
}