using CounterDrone.Core.Simulation;
using Xunit;

namespace CounterDrone.Core.Tests
{
    public class ControlZoneEntityTests
    {
        private const string TestZoneJson =
            "[{\"X\":1200,\"Y\":0,\"Z\":-200},{\"X\":1800,\"Y\":0,\"Z\":-200},{\"X\":1800,\"Y\":0,\"Z\":200},{\"X\":1200,\"Y\":0,\"Z\":200}]";

        [Fact]
        public void ContainsPoint_Center_ReturnsTrue()
        {
            var zone = new ControlZoneEntity("z1", "test", TestZoneJson, 0, 1000);
            // 手动检查顶点数
            Assert.Equal(4, zone.Vertices.Count);
            Assert.Equal(1200f, zone.Vertices[0].X, 1);
            Assert.Equal(-200f, zone.Vertices[0].Z, 1);
            Assert.True(zone.ContainsPoint(1500, 300, 0), "点(1500,300,0)应在矩形内");
        }

        [Fact]
        public void ContainsPoint_OutsideX_ReturnsFalse()
        {
            var zone = new ControlZoneEntity("z1", "test", TestZoneJson, 0, 1000);
            Assert.False(zone.ContainsPoint(2000, 300, 0), "点(2000,300,0)应在矩形外");
        }

        [Fact]
        public void ContainsPoint_OutsideZ_ReturnsFalse()
        {
            var zone = new ControlZoneEntity("z1", "test", TestZoneJson, 0, 1000);
            Assert.False(zone.ContainsPoint(1500, 300, 500), "点(1500,300,500) Z超出");
        }

        [Fact]
        public void ContainsPoint_OutsideAltitude_ReturnsFalse()
        {
            var zone = new ControlZoneEntity("z1", "test", TestZoneJson, 0, 1000);
            Assert.False(zone.ContainsPoint(1500, 1200, 0), "海拔 1200 超出上限");
        }
    }
}
