import 'dart:ui';

import 'package:collection/collection.dart';
import 'package:ecosim/src/common/models/pvector.dart';
import 'package:ecosim/src/ecosim/models/boid.dart';
import 'package:ecosim/src/ecosim/models/world_object.dart';
import 'package:ecosim/src/ecosim/utils.dart';

class SeekingBoid extends Boid {
  SeekingBoid({
    required super.position,
    required super.velocity,
    required super.tickDamage,
    required super.health,
    required super.maxHealth,
    required super.replicationProbability,
    required super.birthTimestamp,
    required super.dna,
    required super.healthyColor,
    required super.unhealthyColor,
    super.r,
    required super.mutationThreshold,
  });

  @override
  void updateBoidDirection(List<List<Object>> objects, Size worldSize) {
    final closestTarget = getClosestItem(
      position,
      dna.foodPerceptionRadius,
      objects.firstWhereOrNull((element) => element.firstOrNull is WorldObject),
      worldSize,
    );
    if (closestTarget != null) {
      PVector steer = getSteeringForce(closestTarget, position, velocity) *
          dna.steeringForce.abs() *
          dna.foodPull;
      acceleration.add(steer);
    }
  }
}
