using System;
using CounterDrone.Core.Algorithms;
using CounterDrone.Core.Models;

namespace CounterDrone.Core.Simulation
{
    public class CloudEntity
    {
        public string Id { get; }
        public ICloudDispersionModel Dispersion { get; }
        public AerosolType AerosolType { get; }
        public float CreatedAt { get; }
        public bool IsDissipated => Dispersion.IsDissipated;

        public CloudEntity(string id, AerosolType aerosolType, ICloudDispersionModel dispersion, float createdAt)
        {
            Id = id;
            AerosolType = aerosolType;
            Dispersion = dispersion;
            CreatedAt = createdAt;
        }

        public void Tick(float deltaTime, float windSpeed, WindDirection windDir)
        {
            Dispersion.Tick(deltaTime, windSpeed, windDir);
        }

        public bool ContainsPoint(float x, float y, float z)
        {
            if (IsDissipated) return false;
            var dx = x - Dispersion.Center.X;
            var dy = y - Dispersion.Center.Y;
            var dz = z - Dispersion.Center.Z;
            var dist = (float)Math.Sqrt(dx * dx + dy * dy + dz * dz);
            return dist <= Dispersion.EffectiveRadius;
        }
    }
}
