using System;
using CounterDrone.Core.Models;

namespace CounterDrone.Core.Algorithms
{
    /// <summary>爆燃式 — 触发型：双条件满足后瞬间高伤害</summary>
    public class ActiveMaterialDamageModel : IDamageModel
    {
        private const float BurstDamage = 0.85f;
        private const float ResidualRate = 0.05f;
        private bool _triggered;

        public float CalculateDamage(TargetType droneType, PowerType powerType,
            AerosolType aerosolType, float cloudDensity, float exposureTime, float deltaTime)
        {
            if (aerosolType != AerosolType.ActiveMaterial) return 0f;

            if (!_triggered)
            {
                _triggered = true;
                var sensitivity = powerType == PowerType.Jet ? 1.3f : 1.0f;
                return BurstDamage * sensitivity;
            }

            return ResidualRate * deltaTime;
        }

        public float RequiredExposureSeconds(TargetType droneType, PowerType powerType, AerosolType aerosolType)
        {
            if (aerosolType != AerosolType.ActiveMaterial) return float.MaxValue;
            var sensitivity = powerType == PowerType.Jet ? 1.3f : 1.0f;
            float burst = BurstDamage * sensitivity;
            if (burst >= 1.0f) return 0f;
            return (1.0f - burst) / ResidualRate;
        }

        public DamageStage GetDamageStage(float accumulatedDamage)
        {
            if (accumulatedDamage >= 1.0f) return DamageStage.Destroyed;
            if (accumulatedDamage >= 0.5f) return DamageStage.AttitudeLoss;
            if (accumulatedDamage >= 0.2f) return DamageStage.EngineAnomaly;
            return DamageStage.Normal;
        }
    }
}
