using System.Collections.Generic;
using Xunit;
using CncModels.Dto;

namespace CncModels.Tests
{
    /// <summary>
    /// ApiResponse<T> 单元测试
    /// </summary>
    public class ApiResponseTests
    {
        [Fact]
        /// <summary>
        /// 成功响应：Code=0, Message=success, Data=传入值
        /// </summary>
        public void Success_Returns_Code_0_Message_Success_With_Data()
        {
            // Arrange
            var data = "ok";
            // Act
            var resp = ApiResponse<string>.Success(data);

            // Assert
            Assert.Equal(0, resp.Code);
            Assert.Equal("success", resp.Message);
            Assert.Equal(data, resp.Data);
        }

        [Fact]
        /// <summary>
        /// 成功响应：自定义信息
        /// </summary>
        public void Success_With_Custom_Message()
        {
            var resp = ApiResponse<string>.Success("payload", "custom");
            Assert.Equal(0, resp.Code);
            Assert.Equal("custom", resp.Message);
            Assert.Equal("payload", resp.Data);
        }

        [Fact]
        /// <summary>
        /// 失败响应：非零错误码且数据为 null
        /// </summary>
        public void Fail_Returns_NonZero_Code_And_Null_Data()
        {
            var resp = ApiResponse<string>.Fail(400, "bad request");
            Assert.Equal(400, resp.Code);
            Assert.Equal("bad request", resp.Message);
            Assert.Null(resp.Data);
        }

        [Fact]
        /// <summary>
        /// 成功响应：数据为 null 的情况
        /// </summary>
        public void Success_With_Null_Data()
        {
            var resp = ApiResponse<string>.Success(null);
            Assert.Equal(0, resp.Code);
            Assert.Equal("success", resp.Message);
            Assert.Null(resp.Data);
        }

        [Fact]
        /// <summary>
        /// 成功响应：复杂对象数据
        /// </summary>
        public void Success_With_Complex_Data()
        {
            var data = new List<int> { 1, 2, 3 };
            var resp = ApiResponse<List<int>>.Success(data);
            Assert.Equal(0, resp.Code);
            Assert.Equal("success", resp.Message);
            Assert.Equal(data, resp.Data);
        }
    }
}
