using CounterDrone.Core.Models;

namespace CounterDrone.Core.Algorithms
{
    /// <summary>默认车道划分：按云团覆盖能力合并或拆分</summary>
    public class DefaultLaneDivider : ILaneDivider
    {
        public (int laneCount, float laneSpacing) Divide(DroneWave wave, float cloudRadius)
        {
            if (wave.Route == null || wave.Quantity <= 1)
                return (1, 0);

            var mode = (FormationMode)wave.Route.FormationMode;
            if (mode != FormationMode.Formation)
                return (1, 0);

            int latCount = wave.Route.LateralCount ?? wave.Quantity;
            int longCount = wave.Route.LongitudinalCount ?? 1;
            float latWidth = (latCount - 1) * (float)wave.Route.LateralSpacing;
            float longDepth = (longCount - 1) * (float)wave.Route.LongitudinalSpacing;
            float cloudDiameter = 2f * cloudRadius;

            // 任一维度超过云团半径，则无法一个云团覆盖
            if (latWidth > cloudRadius || longDepth > cloudRadius)
                return (wave.Quantity, (float)wave.Route.LateralSpacing);

            return (1, 0);
        }
    }
}
