using System;
using UnityEngine;
using URandom = UnityEngine.Random;

public class PlayerModifier : OrbitalBehaviour
{
    public enum Modifiers
    {
        GainPoints,
        FreeHit,
        GrowPlayer,
        ShrinkPlayer,
        ClearAllEnemies,
        SpeedUp
    }

    public static string ModifierToString(Modifiers mod) =>
        mod switch
        {
            Modifiers.GainPoints => "100 Points",
            Modifiers.FreeHit => "Temporary Shield",
            Modifiers.GrowPlayer => "Grow Player",
            Modifiers.ShrinkPlayer => "Shrink Player",
            Modifiers.ClearAllEnemies => "Clear all enemies",
            Modifiers.SpeedUp => "Speed Boost",
            _ => "NULL" 
        };

    private static readonly System.Random s_RandomGenerator = new();

    public Modifiers Modifier { get; private set; }
    
    private static Modifiers GetRandomModifier()
    {
        Array possibilities = Enum.GetValues(typeof(Modifiers));
        return (Modifiers)possibilities.GetValue(s_RandomGenerator.Next(possibilities.Length));
    }

    private void Start()
    {
        RegisterObject(new OrbitalInitializer
        {
            DistanceAlongCircumference = URandom.Range(0f, Mathf.PI * 2f),
            ObjectRadius = 0.3f,
            SpinSpeed = 1.6f
        });
        
        transform.position = new Vector3(0, 0, -100f);
        Modifier = GetRandomModifier();
    }

    protected override void OnOrbitalCollision(OrbitalBehaviour other) => Destroy(gameObject);
    protected override void OnReachCentre() => Destroy(gameObject);

    private void OnDestroy()
    {
        BehaviourManager.UnregisterOrbitalInstance(this);
    }
}
