using System;
using Xunit;
using CncModels.Dto;
using CncModels.Dto.Login;
using CncModels.Dto.Machine;

namespace CncModels.Tests
{
    /// <summary>
    /// PagedQuery 单元测试：覆盖默认值、偏移计算与自动修正逻辑
    /// </summary>
    public class PagedQueryTests
    {
        [Fact]
        /// <summary>
        /// 默认值正确：page=1, pageSize=20, offset=0
        /// </summary>
        public void Page_Defaults_Are_Correct()
        {
            // Arrange/Act
            var q = new PagedQuery();

            // Assert
            Assert.Equal(1, q.Page);
            Assert.Equal(20, q.PageSize);
            Assert.Equal(0, q.Offset);
        }

        [Fact]
        /// <summary>
        /// 标准赋值：Page=3, PageSize=10 -> Offset=20
        /// </summary>
        public void Page_And_PageSize_Normal_Assignments()
        {
            // Arrange
            var q = new PagedQuery
            {
                Page = 3,
                PageSize = 10
            };

            // Assert
            Assert.Equal(3, q.Page);
            Assert.Equal(10, q.PageSize);
            Assert.Equal(20, q.Offset);
        }

        [Fact]
        /// <summary>
        /// 边界：Page=100, PageSize=20
        /// </summary>
        public void Page_Boundary_Normal()
        {
            var q = new PagedQuery { Page = 100, PageSize = 20 };
            Assert.Equal(100, q.Page);
            Assert.Equal(20, q.PageSize);
            Assert.Equal(1980, q.Offset);
        }

        [Fact]
        /// <summary>
        /// 自动修正：Page=0 -> 1
        /// </summary>
        public void Page_AutoFix_When_Zero()
        {
            var q = new PagedQuery { Page = 0 };
            Assert.Equal(1, q.Page);
        }

        [Fact]
        /// <summary>
        /// 自动修正：Page=-5 -> 1
        /// </summary>
        public void Page_AutoFix_When_Negative()
        {
            var q = new PagedQuery { Page = -5 };
            Assert.Equal(1, q.Page);
        }

        [Fact]
        /// <summary>
        /// 自动修正：PageSize=0 -> 20
        /// </summary>
        public void PageSize_AutoFix_When_Zero()
        {
            var q = new PagedQuery { PageSize = 0 };
            Assert.Equal(20, q.PageSize);
        }

        [Fact]
        /// <summary>
        /// 自动修正：PageSize=101 -> 100
        /// </summary>
        public void PageSize_AutoFix_When_Over_Max()
        {
            var q1 = new PagedQuery { PageSize = 101 };
            Assert.Equal(100, q1.PageSize);

            var q2 = new PagedQuery { PageSize = 999 };
            Assert.Equal(100, q2.PageSize);
        }
    }
}
