using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;

namespace AlienAttack.MonoGame.Things.Stars;

internal sealed class Starfield(int seed = 12345)
{
    private readonly List<StarLayer> _layers = [];
    private readonly Random _rng = new(seed);

    public void AddLayer(int count, Vector2 velocityPxPerSec, float minSize, float maxSize, float minAlpha, float maxAlpha)
    {
        _layers.Add(new StarLayer(_rng, count, velocityPxPerSec, minSize, maxSize, minAlpha, maxAlpha));
    }

    public void Initialize(int screenWidth, int screenHeight)
    {
        foreach (var layer in _layers)
            layer.Initialize(screenWidth, screenHeight);
    }

    public void OnResize(int screenWidth, int screenHeight)
    {
        foreach (var layer in _layers)
            layer.OnResize(screenWidth, screenHeight);
    }

    public void Update(GameTime gameTime)
    {
        float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
        foreach (var layer in _layers)
            layer.Update(dt);
    }

    public void Draw(SpriteBatch spriteBatch, Texture2D pixel)
    {
        foreach (var layer in _layers)
            layer.Draw(spriteBatch, pixel);
    }
}