using System;
using CounterDrone.Core.Models;

namespace CounterDrone.Core.Algorithms
{
    /// <summary>吸入式爆炸 — 指数累积型：暴露时间越长伤害越高</summary>
    public class ActiveFuelDamageModel : IDamageModel
    {
        private const float EffectiveThreshold = 0.001f;   // 有效浓度阈值
        private const float BaseRate = 0.02f;             // 基础速率
        private const float ExpFactor = 0.3f;             // 指数增长因子

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

            // 伤害 = 基础速率 × e^(暴露时间 × 因子) × deltaTime
            // 在云团中待得越久伤害指数增长
            var exponential = (float)System.Math.Exp(exposureTime * ExpFactor);
            var damage = BaseRate * exponential * deltaTime;

            // 高速目标更脆弱
            var sensitivity = droneType == TargetType.HighSpeed ? 1.5f : 1.0f;
            return damage * sensitivity;
        }

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