#pragma once

#include "CoreMinimal.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Components/SphereComponent.h"
#include "Bullet.generated.h"

UCLASS()
class YOURGAME_API ABullet : public AActor
{
    GENERATED_BODY()

public:
    ABullet();

protected:
    virtual void BeginPlay() override;

public:
    virtual void Tick(float DeltaTime) override;

    // Function to launch the bullet
    void LaunchBullet(float Speed);

    // Function to accelerate the bullet
    void AccelerateBullet();

    // Function to lock onto a target
    void LockOnToTarget(AActor* Target);

    // Function to track the target's head
    void TrackTargetHead();

    // Function to reset the bullet state
    void ResetBullet();

    // Called when the bullet overlaps with something
    void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

    // Called when the bullet hits something
    void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);

    // Variables
    UPROPERTY(EditDefaultsOnly, Category = "Movement")
    float BaseSpeed;

    UPROPERTY(EditDefaultsOnly, Category = "Movement")
    float MaxSpeed;

    UPROPERTY(EditDefaultsOnly, Category = "Movement")
    float AccelerationDuration;

    UPROPERTY(EditDefaultsOnly, Category = "Tracking")
    float LockOnChance;

    UPROPERTY(EditDefaultsOnly, Category = "Tracking")
    float TrackHeadChance;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
    UProjectileMovementComponent* ProjectileMovement;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
    USphereComponent* SphereComponent;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
    UStaticMeshComponent* BulletMesh;

    UPROPERTY()
    AActor* TargetActor;

    UPROPERTY()
    bool bIsAccelerating;

    UPROPERTY()
    bool bIsTracking;

    float ElapsedTime;
};