using System;
using UnityEngine;

public class Gun : MonoBehaviour
{
    [SerializeField] private FireRateComponent _fireRate;
}

[Serializable]
public class FireRateComponent
{
    [Serializable]
    private enum Type
    {
        Default,
        Automatic,
        SemiAutomatic,
        BoltAction
    }

    [SerializeField] private Type _type = Type.Default;
    [field: SerializeField] public IFireRate Rate { get; }

    public FireRateComponent()
    {
        Rate = _type switch
        {
            Type.Automatic => new AutomaticFireRate(),
            Type.SemiAutomatic => new SemiAutomaticFireRate(),
            Type.BoltAction => new BoltActionFireRate(),
            _ => new DefaultFireRate()
        };
    }
}

public interface IFireRate
{
    public float RoundsPerSecond { get; }
}

[Serializable]
public class DefaultFireRate : IFireRate
{
    public float RoundsPerSecond => 1.0f;
}

[Serializable]
public class AutomaticFireRate : IFireRate
{
    public float RoundsPerSecond => 100.0f;
}

[Serializable]
public class SemiAutomaticFireRate : IFireRate
{
    public float RoundsPerSecond => 0f;
}

[Serializable]
public class BoltActionFireRate : IFireRate
{
    public float RoundsPerSecond => 0f;
}