using OpenTK.Mathematics;

namespace DoomDeathmatch.Component.Util.Collision;

public class AABBColliderComponent : Engine.Scene.Component.Component
{
  public event Action<AABBColliderComponent>? OnCollision;

  public AABBCollider Collider { get; set; } = new();
  public Vector3 Offset { get; set; } = Vector3.Zero;
  public ISet<string> ColliderGroups => _colliderGroups;
  public ISet<string> ExcludeColliderCollideGroups => _excludeColliderCollideGroups;

  private readonly HashSet<string> _colliderGroups = ["default"];
  private readonly HashSet<string> _excludeColliderCollideGroups = [];

  public override void Update(double parDeltaTime)
  {
    Collider.Position = GameObject.Transform.GetFullTranslation() + Offset;
  }

  public void CollideWith(AABBColliderComponent parCollider)
  {
    OnCollision?.Invoke(parCollider);
  }

  public bool InColliderGroup(string parGroup)
  {
    return ColliderGroups.Contains(parGroup);
  }
}