using System;
using CounterDrone.Core.Models;

namespace CounterDrone.Core.Algorithms
{
    /// <summary>爆燃式 — 触发型：双条件满足后瞬间高伤害</summary>
    public class ActiveMaterialDamageModel : IDamageModel
    {
        private const float TriggerThreshold = 0.0002f;      // 触发浓度阈值
        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 (cloudDensity < TriggerThreshold) return 0f;

            // 喷气发动机高温触发爆燃，更敏感
            if (!_triggered)
            {
                _triggered = true;
                var sensitivity = powerType == PowerType.Jet ? 1.3f : 1.0f;
                return BurstDamage * sensitivity;
            }

            return ResidualRate * deltaTime;
        }

        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;
        }
    }
}
