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

namespace CncModels.Tests
{
    /// <summary>
    /// DTO 属性赋值测试（对关键 DTO 的简单结构进行读写回填验证）
    /// </summary>
    public class DtoTests
    {
        [Fact]
        /// <summary>
        /// LoginRequest 属性赋值读取回填
        /// </summary>
        public void LoginRequest_Property_Assignment()
        {
            // Arrange
            var req = new LoginRequest
            {
                Username = "user1",
                Password = "pwd",
                RememberMe = true
            };

            // Assert
            Assert.Equal("user1", req.Username);
            Assert.Equal("pwd", req.Password);
            Assert.True(req.RememberMe);
        }

        [Fact]
        /// <summary>
        /// MachineQuery 继承自 PagedQuery 且字段赋值正确
        /// </summary>
        public void MachineQuery_Inherits_PagedQuery_And_Sets_Others()
        {
            var q = new MachineQuery
            {
                Page = 2,
                PageSize = 5,
                Keyword = "lathe",
                WorkshopId = 3,
                IsOnline = 1,
                BrandId = 7
            };

            Assert.Equal(2, q.Page);
            Assert.Equal(5, q.PageSize);
            Assert.Equal("lathe", q.Keyword);
            Assert.Equal(3, q.WorkshopId);
            Assert.Equal(1, q.IsOnline);
            Assert.Equal(7, q.BrandId);
            Assert.Equal(5, q.Offset); // (2-1)*5
        }

        [Fact]
        /// <summary>
        /// CreateMachineRequest 属性赋值读取回填
        /// </summary>
        public void CreateMachineRequest_Property_Assignment()
        {
            var req = new CreateMachineRequest
            {
                DeviceCode = "D1",
                Name = "Machine 1",
                WorkshopId = 2,
                CollectAddressId = 3,
                IpAddress = "192.168.1.10",
                BrandId = 8
            };

            Assert.Equal("D1", req.DeviceCode);
            Assert.Equal("Machine 1", req.Name);
            Assert.Equal(2, req.WorkshopId);
            Assert.Equal(3, req.CollectAddressId);
            Assert.Equal("192.168.1.10", req.IpAddress);
            Assert.Equal(8, req.BrandId);
        }

        [Fact]
        /// <summary>
        /// MachineListItem 属性赋值读取回填
        /// </summary>
        public void MachineListItem_Property_Assignment()
        {
            var item = new MachineListItem
            {
                Id = 1,
                DeviceCode = "M1",
                Name = "Machine 1",
                WorkshopId = 2,
                WorkshopName = "Workshop A",
                CollectAddressId = 4,
                BrandId = 8,
                BrandName = "BrandX",
                IpAddress = "10.0.0.1",
                IsEnabled = true,
                IsOnline = true,
                WorkerId = 9,
                WorkerName = "Worker1",
                LastProgramName = "P1",
                LastCollectTime = new DateTime(2026, 4, 1)
            };

            Assert.Equal(1, item.Id);
            Assert.Equal("M1", item.DeviceCode);
            Assert.Equal("Machine 1", item.Name);
            Assert.Equal(2, item.WorkshopId);
            Assert.Equal("Workshop A", item.WorkshopName);
            Assert.Equal(4, item.CollectAddressId);
            Assert.Equal(8, item.BrandId);
            Assert.Equal("BrandX", item.BrandName);
            Assert.Equal("10.0.0.1", item.IpAddress);
            Assert.True(item.IsEnabled);
            Assert.True(item.IsOnline);
            Assert.Equal(9, item.WorkerId);
            Assert.Equal("Worker1", item.WorkerName);
            Assert.Equal("P1", item.LastProgramName);
            Assert.Equal(new DateTime(2026, 4, 1), item.LastCollectTime);
        }
    }
}
