using System;
using CncModels.Entity;
using Xunit;

namespace CncModels.Tests
{
    public class EntityTests
    {
        // Workshop
        [Fact]
        public void Workshop_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            // Arrange: defaults
            var w0 = new Workshop();
            Assert.Equal(0, w0.Id);
            Assert.Null(w0.Name);
            Assert.Equal(0, w0.SortOrder);
            Assert.Equal(0, w0.IsEnabled);
            Assert.Equal(default(DateTime), w0.CreatedAt);
            Assert.Equal(default(DateTime), w0.UpdatedAt);

            // Act: assign all fields
            var w = new Workshop
            {
                Id = 1,
                Name = "A栋",
                SortOrder = 2,
                IsEnabled = 1,
                CreatedAt = new DateTime(2026, 4, 28),
                UpdatedAt = new DateTime(2026, 4, 29)
            };

            // Assert: values
            Assert.Equal(1, w.Id);
            Assert.Equal("A栋", w.Name);
            Assert.Equal(2, w.SortOrder);
            Assert.Equal(1, w.IsEnabled);
            Assert.Equal(new DateTime(2026, 4, 28), w.CreatedAt);
            Assert.Equal(new DateTime(2026, 4, 29), w.UpdatedAt);
        }

        // Brand
        [Fact]
        public void Brand_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var b0 = new Brand();
            Assert.Equal(0, b0.Id);
            Assert.Null(b0.BrandName);
            Assert.Null(b0.DeviceField);
            Assert.Null(b0.TagsPath);
            Assert.Equal(0, b0.IsEnabled);
            Assert.Equal(default(DateTime), b0.CreatedAt);
            Assert.Equal(default(DateTime), b0.UpdatedAt);

            var b = new Brand
            {
                Id = 3,
                BrandName = "BrandX",
                DeviceField = "fieldX",
                TagsPath = "/tags/x",
                IsEnabled = 1,
                CreatedAt = new DateTime(2026, 4, 28),
                UpdatedAt = new DateTime(2026, 4, 29)
            };
            Assert.Equal(3, b.Id);
            Assert.Equal("BrandX", b.BrandName);
            Assert.Equal("fieldX", b.DeviceField);
            Assert.Equal("/tags/x", b.TagsPath);
            Assert.Equal(1, b.IsEnabled);
            Assert.Equal(new DateTime(2026, 4, 28), b.CreatedAt);
            Assert.Equal(new DateTime(2026, 4, 29), b.UpdatedAt);
        }

        // BrandFieldMapping
        [Fact]
        public void BrandFieldMapping_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var m0 = new BrandFieldMapping();
            Assert.Equal(0, m0.Id);
            Assert.Equal(0, m0.BrandId);
            Assert.Null(m0.StandardField);
            Assert.Null(m0.FieldName);
            Assert.Null(m0.MatchBy);
            Assert.Null(m0.DataType);
            Assert.Equal(0, m0.IsRequired);
            Assert.Equal(default(DateTime), m0.CreatedAt);

            var m = new BrandFieldMapping
            {
                Id = 1,
                BrandId = 2,
                StandardField = "Model",
                FieldName = "mdl",
                MatchBy = "equals",
                DataType = "string",
                IsRequired = 1,
                CreatedAt = new DateTime(2026, 4, 28)
            };
            Assert.Equal(1, m.Id);
            Assert.Equal(2, m.BrandId);
            Assert.Equal("Model", m.StandardField);
            Assert.Equal("mdl", m.FieldName);
            Assert.Equal("equals", m.MatchBy);
            Assert.Equal("string", m.DataType);
            Assert.Equal(1, m.IsRequired);
            Assert.Equal(new DateTime(2026, 4, 28), m.CreatedAt);
        }

        // CollectAddress
        [Fact]
        public void CollectAddress_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var a0 = new CollectAddress();
            Assert.Equal(0, a0.Id);
            Assert.Null(a0.Name);
            Assert.Null(a0.Url);
            Assert.Equal(0, a0.BrandId);
            Assert.Equal(0, a0.CollectInterval);
            Assert.Equal(0, a0.IsEnabled);
            Assert.Null(a0.LastCollectTime);
            Assert.Null(a0.LastCollectStatus);
            Assert.Equal(0, a0.FailCount);
            Assert.Equal(default(DateTime), a0.CreatedAt);
            Assert.Equal(default(DateTime), a0.UpdatedAt);

            var a = new CollectAddress
            {
                Id = 10,
                Name = "地址1",
                Url = "http://127.0.0.1",
                BrandId = 5,
                CollectInterval = 60,
                IsEnabled = 1,
                LastCollectTime = new DateTime(2026, 4, 28),
                LastCollectStatus = "OK",
                FailCount = 0,
                CreatedAt = new DateTime(2026, 4, 29),
                UpdatedAt = new DateTime(2026, 4, 30)
            };
            Assert.Equal(10, a.Id);
            Assert.Equal("地址1", a.Name);
            Assert.Equal("http://127.0.0.1", a.Url);
            Assert.Equal(5, a.BrandId);
            Assert.Equal(60, a.CollectInterval);
            Assert.Equal(1, a.IsEnabled);
            Assert.Equal(new DateTime(2026, 4, 28), a.LastCollectTime);
            Assert.Equal("OK", a.LastCollectStatus);
            Assert.Equal(0, a.FailCount);
            Assert.Equal(new DateTime(2026, 4, 29), a.CreatedAt);
            Assert.Equal(new DateTime(2026, 4, 30), a. UpdatedAt);
        }

        // CollectRecord
        [Fact]
        public void CollectRecord_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var r0 = new CollectRecord();
            Assert.Equal(0L, r0.Id);
            Assert.Equal(default(DateTime), r0.CollectTime);
            Assert.Equal(0, r0.MachineId);
            Assert.Null(r0.ProgramName);
            Assert.Null(r0.DeviceStatus);
            Assert.Null(r0.RunStatus);
            Assert.Null(r0.OperateMode);
            Assert.Null(r0.ExtraData);

            var r = new CollectRecord
            {
                Id = 1234567890123,
                MachineId = 7,
                CollectTime = new DateTime(2026, 4, 28, 12, 0, 0),
                DeviceTime = new DateTime(2026, 4, 28, 12, 0, 1),
                ProgramName = "Prog1",
                PartCount = 99.5m,
                DeviceStatus = "OK",
                RunStatus = "Running",
                OperateMode = "Auto",
                SpindleSpeedSet = 1500.0m,
                FeedSpeedSet = 200.0m,
                SpindleSpeedActual = 1499.0m,
                FeedSpeedActual = 198.0m,
                SpindleLoad = 75.0m,
                SpindleOverride = 1.0m,
                PowerOnTime = 3600.0m,
                RunTime = 7200.0m,
                CuttingTime = 1800.0m,
                CycleTime = 300.0m,
                MachiningStatus = "Machining",
                ExtraData = "{}",
            };
            // Partial assertions to cover types
            Assert.Equal(1234567890123, r.Id);
            Assert.Equal(7, r.MachineId);
            Assert.Equal(new DateTime(2026, 4, 28, 12, 0, 0), r.CollectTime);
            Assert.Equal("Prog1", r.ProgramName);
            Assert.Equal(99.5m, r.PartCount);
            Assert.Equal("OK", r.DeviceStatus);
            Assert.Equal("Running", r.RunStatus);
            Assert.Equal(1500.0m, r.SpindleSpeedSet);
            Assert.Equal(200.0m, r.FeedSpeedSet);
            Assert.Equal("Machining", r.MachiningStatus);
        }

        // ProductionSegment
        [Fact]
        public void ProductionSegment_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var s0 = new ProductionSegment();
            Assert.Equal(0L, s0.Id);
            Assert.Equal(0, s0.MachineId);
            Assert.Null(s0.ProgramName);
            Assert.Equal(default(DateTime), s0.ProductionDate);
            Assert.Equal(default(DateTime), s0.StartTime);
            Assert.Null(s0.EndTime);
            Assert.Equal(0m, s0.StartPartCount);
            Assert.Null(s0.EndPartCount);
            Assert.Null(s0.Quantity);
            Assert.Equal(0, s0.IsSettled);
            Assert.Null(s0.CloseReason);
            Assert.Equal(default(DateTime), s0.CreatedAt);
            Assert.Equal(default(DateTime), s0.UpdatedAt);

            var s = new ProductionSegment
            {
                Id = 1,
                MachineId = 2,
                ProgramName = "Prog",
                ProductionDate = new DateTime(2026, 4, 28),
                StartTime = new DateTime(2026, 4, 28, 8, 0, 0),
                EndTime = new DateTime(2026, 4, 28, 12, 0, 0),
                StartPartCount = 10.0m,
                EndPartCount = 20.0m,
                Quantity = 10.0m,
                IsSettled = 1,
                CloseReason = "End",
                CreatedAt = new DateTime(2026, 4, 28),
                UpdatedAt = new DateTime(2026, 4, 29)
            };
            Assert.Equal(1, s.Id);
            Assert.Equal(2, s.MachineId);
            Assert.Equal("Prog", s.ProgramName);
            Assert.Equal(new DateTime(2026, 4, 28), s.ProductionDate);
            Assert.Equal(new DateTime(2026, 4, 28, 8, 0, 0), s.StartTime);
            Assert.Equal(new DateTime(2026, 4, 28, 12, 0, 0), s.EndTime);
            Assert.Equal(10.0m, s.StartPartCount);
            Assert.Equal(20.0m, s.EndPartCount);
            Assert.Equal(10.0m, s.Quantity);
            Assert.Equal(1, s.IsSettled);
            Assert.Equal("End", s.CloseReason);
            Assert.Equal(new DateTime(2026, 4, 28), s.CreatedAt);
            Assert.Equal(new DateTime(2026, 4, 29), s.UpdatedAt);
        }

        // MachineDailyStatus
        [Fact]
        public void MachineDailyStatus_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var m0 = new MachineDailyStatus();
            Assert.Equal(0, m0.Id);
            Assert.Equal(0, m0.MachineId);
            Assert.Null(m0.DataStatus);
            Assert.Equal(default(DateTime), m0.CreatedAt);
            Assert.Equal(default(DateTime), m0.UpdatedAt);

            var m = new MachineDailyStatus
            {
                Id = 5,
                MachineId = 9,
                ProductionDate = new DateTime(2026, 4, 28),
                DataStatus = "Online",
                CreatedAt = new DateTime(2026, 4, 28),
                UpdatedAt = new DateTime(2026, 4, 29)
            };
            Assert.Equal(5, m.Id);
            Assert.Equal(9, m.MachineId);
            Assert.Equal("Online", m.DataStatus);
            Assert.Equal(new DateTime(2026, 4, 28), m.ProductionDate);
            Assert.Equal(new DateTime(2026, 4, 28), m.CreatedAt);
            Assert.Equal(new DateTime(2026, 4, 29), m.UpdatedAt);
        }

        // DailyProduction
        [Fact]
        public void DailyProduction_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var d0 = new DailyProduction();
            Assert.Equal(0, d0.Id);
            Assert.Equal(0, d0.MachineId);
            Assert.Equal(default(DateTime), d0.ProductionDate);
            Assert.Null(d0.ProgramName);
            Assert.Equal(0m, d0.TotalQuantity);
            Assert.Equal(0, d0.SegmentCount);
            Assert.Null(d0.TotalRunTime);
            Assert.Null(d0.TotalCuttingTime);
            Assert.Null(d0.TotalCycleTime);
            Assert.Equal(0, d0.IsAdjusted);
            Assert.Null(d0.AdjustedQuantity);
            Assert.Equal(default(DateTime), d0.CreatedAt);
            Assert.Equal(default(DateTime), d0.UpdatedAt);

            var d = new DailyProduction
            {
                Id = 2,
                MachineId = 3,
                ProductionDate = new DateTime(2026, 4, 28),
                ProgramName = "ProgA",
                TotalQuantity = 100.5m,
                SegmentCount = 5,
                TotalRunTime = 3600.0m,
                TotalCuttingTime = 1800.0m,
                TotalCycleTime = 1200.0m,
                IsAdjusted = 0,
                AdjustedQuantity = 0.0m,
                CreatedAt = new DateTime(2026, 4, 28),
                UpdatedAt = new DateTime(2026, 4, 29)
            };
            Assert.Equal(2, d.Id);
            Assert.Equal(3, d.MachineId);
            Assert.Equal("ProgA", d.ProgramName);
            Assert.Equal(new DateTime(2026, 4, 28), d.ProductionDate);
            Assert.Equal(100.5m, d.TotalQuantity);
            Assert.Equal(5, d.SegmentCount);
            Assert.Equal(3600.0m, d.TotalRunTime);
            Assert.Equal(1800.0m, d.TotalCuttingTime);
            Assert.Equal(1200.0m, d.TotalCycleTime);
            Assert.Equal(0, d.IsAdjusted);
            Assert.Equal(new DateTime(2026, 4, 28), d.CreatedAt);
            Assert.Equal(new DateTime(2026, 4, 29), d.UpdatedAt);
        }

        // WorkerDailySummary
        [Fact]
        public void WorkerDailySummary_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var w0 = new WorkerDailySummary();
            Assert.Equal(0, w0.Id);
            Assert.Equal(0, w0.WorkerId);
            Assert.Equal(default(DateTime), w0.ProductionDate);
            Assert.Equal(0m, w0.TotalQuantity);
            Assert.Equal(0, w0.MachineCount);
            Assert.Equal(0, w0.ProgramCount);
            Assert.Equal(0, w0.IsAdjusted);
            Assert.Null(w0.AdjustedQuantity);
            Assert.Equal(default(DateTime), w0.CreatedAt);
            Assert.Equal(default(DateTime), w0.UpdatedAt);

            var w = new WorkerDailySummary
            {
                Id = 7,
                WorkerId = 8,
                ProductionDate = new DateTime(2026, 4, 28),
                TotalQuantity = 45.0m,
                MachineCount = 2,
                ProgramCount = 3,
                IsAdjusted = 1,
                AdjustedQuantity = 44.5m,
                CreatedAt = new DateTime(2026, 4, 28),
                UpdatedAt = new DateTime(2026, 4, 29)
            };
            Assert.Equal(7, w.Id);
            Assert.Equal(8, w.WorkerId);
            Assert.Equal(new DateTime(2026, 4, 28), w.ProductionDate);
            Assert.Equal(45.0m, w.TotalQuantity);
            Assert.Equal(2, w.MachineCount);
            Assert.Equal(3, w.ProgramCount);
            Assert.Equal(1, w.IsAdjusted);
            Assert.Equal(44.5m, w.AdjustedQuantity);
            Assert.Equal(new DateTime(2026, 4, 28), w.CreatedAt);
            Assert.Equal(new DateTime(2026, 4, 29), w.UpdatedAt);
        }

        // ProductionAdjustment
        [Fact]
        public void ProductionAdjustment_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var a0 = new ProductionAdjustment();
            Assert.Equal(0L, a0.Id);
            Assert.Null(a0.TargetTable);
            Assert.Equal(0, a0.TargetId);
            Assert.Null(a0.FieldName);
            Assert.Null(a0.OldValue);
            Assert.Equal(0m, a0.NewValue);
            Assert.Null(a0.Reason);
            Assert.Null(a0.OperatorIp);
            Assert.Equal(default(DateTime), a0.CreatedAt);

            var a = new ProductionAdjustment
            {
                Id = 1,
                TargetTable = "cnc_daily_production",
                TargetId = 2,
                FieldName = "TotalQuantity",
                OldValue = 10.0m,
                NewValue = 12.5m,
                Reason = "Adjustment",
                OperatorIp = "127.0.0.1",
                CreatedAt = new DateTime(2026, 4, 28)
            };
            Assert.Equal(1, a.Id);
            Assert.Equal("cnc_daily_production", a.TargetTable);
            Assert.Equal(2, a.TargetId);
            Assert.Equal("TotalQuantity", a.FieldName);
            Assert.Equal(10.0m, a.OldValue);
            Assert.Equal(12.5m, a.NewValue);
            Assert.Equal("Adjustment", a.Reason);
            Assert.Equal("127.0.0.1", a.OperatorIp);
            Assert.Equal(new DateTime(2026, 4, 28), a.CreatedAt);
        }

        // Alert
        [Fact]
        public void Alert_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var al0 = new Alert();
            Assert.Equal(0L, al0.Id);
            Assert.Null(al0.AlertType);
            Assert.Null(al0.Title);
            Assert.Null(al0.Detail);
            Assert.Equal(0, al0.IsResolved);
            Assert.Equal(default(DateTime), al0.CreatedAt);
            Assert.Null(al0.ResolvedAt);

            var al = new Alert
            {
                Id = 1,
                AlertType = "Error",
                MachineId = 5,
                CollectAddressId = 6,
                Title = "Alarm",
                Detail = "Detail",
                IsResolved = 1,
                ResolvedAt = new DateTime(2026, 4, 28),
                CreatedAt = new DateTime(2026, 4, 28)
            };
            Assert.Equal(1, al.Id);
            Assert.Equal("Error", al.AlertType);
            Assert.Equal(5, al.MachineId);
            Assert.Equal(6, al.CollectAddressId);
            Assert.Equal("Alarm", al.Title);
            Assert.Equal("Detail", al.Detail);
            Assert.Equal(1, al.IsResolved);
            Assert.Equal(new DateTime(2026, 4, 28), al.ResolvedAt);
            Assert.Equal(new DateTime(2026, 4, 28), al.CreatedAt);
        }

        // SysConfig
        [Fact]
        public void SysConfig_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var s0 = new SysConfig();
            Assert.Equal(0, s0.Id);
            Assert.Null(s0.ConfigKey);
            Assert.Null(s0.ConfigValue);
            Assert.Null(s0.ValueType);
            Assert.Null(s0.Description);
            Assert.Equal(default(DateTime), s0.UpdatedAt);

            var s = new SysConfig
            {
                Id = 1,
                ConfigKey = "MaxThreads",
                ConfigValue = "4",
                ValueType = "int",
                Description = "最大线程数",
                UpdatedAt = new DateTime(2026, 4, 29)
            };
            Assert.Equal(1, s.Id);
            Assert.Equal("MaxThreads", s.ConfigKey);
            Assert.Equal("4", s.ConfigValue);
            Assert.Equal("int", s.ValueType);
            Assert.Equal("最大线程数", s.Description);
            Assert.Equal(new DateTime(2026, 4, 29), s.UpdatedAt);
        }

        // ScreenConfig
        [Fact]
        public void ScreenConfig_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var sc0 = new ScreenConfig();
            Assert.Equal(0, sc0.Id);
            Assert.Null(sc0.CardKey);
            Assert.Null(sc0.ChartConfig);
            Assert.Equal(default(DateTime), sc0.CreatedAt);
            Assert.Equal(default(DateTime), sc0.UpdatedAt);

            var sc = new ScreenConfig
            {
                Id = 2,
                CardKey = "card-1",
                CardType = "typeA",
                Title = "Title",
                Metric = "metric",
                Dimension = "dim",
                SortOrder = 1,
                IsEnabled = 1,
                ChartConfig = "{...}",
                CreatedAt = new DateTime(2026, 4, 28),
                UpdatedAt = new DateTime(2026, 4, 29)
            };
            Assert.Equal(2, sc.Id);
            Assert.Equal("card-1", sc.CardKey);
            Assert.Equal("typeA", sc.CardType);
            Assert.Equal("Title", sc.Title);
            Assert.Equal("metric", sc.Metric);
            Assert.Equal("dim", sc.Dimension);
            Assert.Equal(1, sc.SortOrder);
            Assert.Equal(1, sc.IsEnabled);
            Assert.Equal("{...}", sc.ChartConfig);
            Assert.Equal(new DateTime(2026, 4, 28), sc.CreatedAt);
            Assert.Equal(new DateTime(2026, 4, 29), sc.UpdatedAt);
        }

        // ScreenFilter
        [Fact]
        public void ScreenFilter_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var sf0 = new ScreenFilter();
            Assert.Equal(0, sf0.Id);
            Assert.Null(sf0.ScreenKey);
            Assert.Null(sf0.FilterType);
            Assert.Null(sf0.FilterValue);
            Assert.Equal(0, sf0.IsDefault);
            Assert.Equal(0, sf0.SortOrder);

            var sf = new ScreenFilter
            {
                Id = 3,
                ScreenKey = "key1",
                FilterType = "type",
                FilterValue = "value",
                IsDefault = 1,
                SortOrder = 2
            };
            Assert.Equal(3, sf.Id);
            Assert.Equal("key1", sf.ScreenKey);
            Assert.Equal("type", sf.FilterType);
            Assert.Equal("value", sf.FilterValue);
            Assert.Equal(1, sf.IsDefault);
            Assert.Equal(2, sf.SortOrder);
        }

        // CollectRaw
        [Fact]
        public void CollectRaw_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var cr0 = new CollectRaw();
            Assert.Equal(0L, cr0.Id);
            Assert.Equal(0, cr0.CollectAddressId);
            Assert.Equal(default(DateTime), cr0.RequestTime);
            Assert.Equal(default(DateTime), cr0.ResponseTime);
            Assert.Null(cr0.ResponseDuration);
            Assert.Equal(0, cr0.IsSuccess);
            Assert.Null(cr0.StatusCode);
            Assert.Null(cr0.RawJson);
            Assert.Null(cr0.ErrorMessage);
            Assert.Equal(default(DateTime), cr0.CreatedAt);

            var cr = new CollectRaw
            {
                Id = 1,
                CollectAddressId = 2,
                RequestTime = new DateTime(2026, 4, 28, 10, 0, 0),
                ResponseTime = new DateTime(2026, 4, 28, 10, 0, 1),
                ResponseDuration = 100,
                IsSuccess = 1,
                StatusCode = 200,
                RawJson = "{\"a\":1}",
                ErrorMessage = null,
                CreatedAt = new DateTime(2026, 4, 28)
            };
            Assert.Equal(1, cr.Id);
            Assert.Equal(2, cr.CollectAddressId);
            Assert.Equal(new DateTime(2026, 4, 28, 10, 0, 0), cr.RequestTime);
            Assert.Equal(new DateTime(2026, 4, 28, 10, 0, 1), cr.ResponseTime);
            Assert.Equal(100, cr.ResponseDuration);
            Assert.Equal(1, cr.IsSuccess);
            Assert.Equal(200, cr.StatusCode);
            Assert.Equal("{\"a\":1}", cr.RawJson);
            Assert.Null(cr.ErrorMessage);
            Assert.Equal(new DateTime(2026, 4, 28), cr.CreatedAt);
        }

        // SystemLog
        [Fact]
        public void SystemLog_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var sl0 = new SystemLog();
            Assert.Equal(0L, sl0.Id);
            Assert.Null(sl0.LogLevel);
            Assert.Null(sl0.Source);
            Assert.Null(sl0.Message);
            Assert.Null(sl0.StackTrace);
            Assert.Null(sl0.ExtraData);
            Assert.Equal(default(DateTime), sl0.CreatedAt);

            var sl = new SystemLog
            {
                Id = 9,
                LogLevel = "Info",
                Source = "SourceA",
                Message = "msg",
                StackTrace = "trace",
                ExtraData = "{}",
                CreatedAt = new DateTime(2026, 4, 28)
            };
            Assert.Equal(9, sl.Id);
            Assert.Equal("Info", sl.LogLevel);
            Assert.Equal("SourceA", sl.Source);
            Assert.Equal("msg", sl.Message);
            Assert.Equal("trace", sl.StackTrace);
            Assert.Equal("{}", sl.ExtraData);
            Assert.Equal(new DateTime(2026, 4, 28), sl.CreatedAt);
        }

        // CollectorHeartbeat
        [Fact]
        public void CollectorHeartbeat_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var cb0 = new CollectorHeartbeat();
            Assert.Equal(0L, cb0.Id);
            Assert.Null(cb0.ServiceId);
            Assert.Null(cb0.Status);
            Assert.Null(cb0.Detail);
            Assert.Null(cb0.LastCollectTime);
            Assert.Equal(0, cb0.SuccessCount);
            Assert.Equal(0, cb0.FailCount);
            Assert.Null(cb0.UptimeSeconds);
            Assert.Equal(default(DateTime), cb0.CreatedAt);

            var cb = new CollectorHeartbeat
            {
                Id = 11,
                ServiceId = "svc-1",
                Status = "Healthy",
                CollectAddressId = 4,
                LastCollectTime = new DateTime(2026, 4, 28, 12, 0, 0),
                SuccessCount = 10,
                FailCount = 1,
                UptimeSeconds = 3600,
                Detail = "{}",
                CreatedAt = new DateTime(2026, 4, 28)
            };
            Assert.Equal(11, cb.Id);
            Assert.Equal("svc-1", cb.ServiceId);
            Assert.Equal("Healthy", cb.Status);
            Assert.Equal(4, cb.CollectAddressId);
            Assert.Equal(new DateTime(2026, 4, 28, 12, 0, 0), cb.LastCollectTime);
            Assert.Equal(10, cb.SuccessCount);
            Assert.Equal(1, cb.FailCount);
            Assert.Equal(3600, cb.UptimeSeconds);
            Assert.Equal("{}", cb.Detail);
            Assert.Equal(new DateTime(2026, 4, 28), cb.CreatedAt);
        }

        // Machine
        [Fact]
        public void Machine_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var m0 = new Machine();
            Assert.Equal(0, m0.Id);
            Assert.Null(m0.DeviceCode);
            Assert.Null(m0.Name);
            Assert.Equal(0, m0.WorkshopId);
            Assert.Equal(0, m0.CollectAddressId);
            Assert.Null(m0.IpAddress);
            Assert.Equal(0, m0.BrandId);
            Assert.Equal(0, m0.IsEnabled);
            Assert.Null(m0.LastPingTime);
            Assert.Null(m0.LastCollectTime);
            Assert.Null(m0.LastDeviceStatus);
            Assert.Null(m0.LastRunStatus);
            Assert.Null(m0.LastProgramName);
            Assert.Null(m0.LastPartCount);
            Assert.Null(m0.LastOperateMode);
            Assert.Null(m0.LastMachiningStatus);
            Assert.Equal(default(DateTime), m0.CreatedAt);
            Assert.Equal(default(DateTime), m0.UpdatedAt);

            var m = new Machine
            {
                Id = 10,
                DeviceCode = "M-10",
                Name = "Machine10",
                WorkshopId = 1,
                CollectAddressId = 2,
                IpAddress = "192.168.0.10",
                BrandId = 3,
                IsEnabled = 1,
                LastPingTime = new DateTime(2026, 4, 28, 12, 0, 0),
                LastCollectTime = new DateTime(2026, 4, 28, 12, 5, 0),
                LastDeviceStatus = "OK",
                LastRunStatus = "Running",
                LastProgramName = "Prog1",
                LastPartCount = 42.0m,
                LastOperateMode = "Auto",
                LastMachiningStatus = "Active",
                CreatedAt = new DateTime(2026, 4, 28),
                UpdatedAt = new DateTime(2026, 4, 29)
            };
            Assert.Equal(10, m.Id);
            Assert.Equal("M-10", m.DeviceCode);
            Assert.Equal("Machine10", m.Name);
            Assert.Equal(1, m.WorkshopId);
            Assert.Equal(2, m.CollectAddressId);
            Assert.Equal("192.168.0.10", m.IpAddress);
            Assert.Equal(3, m.BrandId);
            Assert.Equal(1, m.IsEnabled);
            Assert.Equal(new DateTime(2026, 4, 28, 12, 0, 0), m.LastPingTime);
            Assert.Equal(new DateTime(2026, 4, 28, 12, 5, 0), m.LastCollectTime);
            Assert.Equal("OK", m.LastDeviceStatus);
            Assert.Equal("Running", m.LastRunStatus);
            Assert.Equal("Prog1", m.LastProgramName);
            Assert.Equal(42.0m, m.LastPartCount);
            Assert.Equal("Auto", m.LastOperateMode);
            Assert.Equal("Active", m.LastMachiningStatus);
            Assert.Equal(new DateTime(2026, 4, 28), m.CreatedAt);
            Assert.Equal(new DateTime(2026, 4, 29), m.UpdatedAt);
        }

        // Worker
        [Fact]
        public void Worker_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var w0 = new Worker();
            Assert.Equal(0, w0.Id);
            Assert.Null(w0.Name);
            Assert.Null(w0.Code);
            Assert.Equal(0, w0.IsEnabled);
            Assert.Equal(default(DateTime), w0.CreatedAt);
            Assert.Equal(default(DateTime), w0.UpdatedAt);

            var w = new Worker
            {
                Id = 2,
                Name = "张三",
                Code = "W-2",
                IsEnabled = 1,
                CreatedAt = new DateTime(2026, 4, 28),
                UpdatedAt = new DateTime(2026, 4, 29)
            };
            Assert.Equal(2, w.Id);
            Assert.Equal("张三", w.Name);
            Assert.Equal("W-2", w.Code);
            Assert.Equal(1, w.IsEnabled);
            Assert.Equal(new DateTime(2026, 4, 28), w.CreatedAt);
            Assert.Equal(new DateTime(2026, 4, 29), w.UpdatedAt);
        }

        // WorkerMachine
        [Fact]
        public void WorkerMachine_DefaultsAndAssignments_ReturnsCorrectValues()
        {
            var wm0 = new WorkerMachine();
            Assert.Equal(0, wm0.Id);
            Assert.Equal(0, wm0.WorkerId);
            Assert.Equal(0, wm0.MachineId);
            Assert.Equal(default(DateTime), wm0.CreatedAt);

            var wm = new WorkerMachine
            {
                Id = 1,
                WorkerId = 2,
                MachineId = 3,
                CreatedAt = new DateTime(2026, 4, 28)
            };
            Assert.Equal(1, wm.Id);
            Assert.Equal(2, wm.WorkerId);
            Assert.Equal(3, wm.MachineId);
            Assert.Equal(new DateTime(2026, 4, 28), wm.CreatedAt);
        }
    }
}
