using System.Collections.Generic;
using UnityEngine;

public abstract class Rule
{
    [SerializeField]
    private float m_ruleDuration = 5f;

    [Range(0f, 100f)]
    [SerializeField]
    [Tooltip("Min time before to spawn an enemie in second")]
    private float m_minTimeBeforeSpawn = 0.5f;

    [Range(0f, 100f)]
    [SerializeField]
    [Tooltip("Max time before to spawn an enemie in second")]
    private float m_maxTimeBeforeSpawn = 1.5f;

    [SerializeField]
    protected List<GameObject> m_prefabs;

    private float m_currentRuleTime;
    private float m_nextSpawnTime;

    public void StartRule()
    {
        m_currentRuleTime = m_ruleDuration;
        UpdateNextSpawn();
    }

    public bool Update()
    {
        m_currentRuleTime -= Time.deltaTime;

        m_nextSpawnTime -= Time.deltaTime;
        if (m_nextSpawnTime <= 0f)
        {
            UpdateNextSpawn();

            ApplyRule();
        }


        return m_currentRuleTime <= 0f;
    }

    protected abstract void ApplyRule();

    private void UpdateNextSpawn()
    {
        m_nextSpawnTime = UnityEngine.Random.Range(m_minTimeBeforeSpawn, m_maxTimeBeforeSpawn);
    }
}
