using System.Collections.Generic;
using Newtonsoft.Json;

namespace CncSimulator.Config
{
    /// <summary>模拟器顶层配置</summary>
    public class SimulatorConfig
    {
        /// <summary>总管理页面端口</summary>
        [JsonProperty("gatewayPort")]
        public int GatewayPort { get; set; } = 9000;

        /// <summary>数据库连接字符串</summary>
        [JsonProperty("dbConnection")]
        public string DbConnection { get; set; } = "Server=localhost;Database=cnc_business;Uid=root;Pwd=root;Charset=utf8mb4;SslMode=None;";

        /// <summary>数据变化频率（秒）- 全局默认值</summary>
        [JsonProperty("defaultDataChangeInterval")]
        public int DefaultDataChangeInterval { get; set; } = 10;

        /// <summary>采集地址列表（运行时动态创建）</summary>
        [JsonProperty("addresses")]
        public List<AddressConfig> Addresses { get; set; } = new List<AddressConfig>();
    }

    /// <summary>单个采集地址配置</summary>
    public class AddressConfig
    {
        /// <summary>数据库中的采集地址ID</summary>
        [JsonProperty("dbAddressId")]
        public int DbAddressId { get; set; }

        /// <summary>显示名称</summary>
        [JsonProperty("name")]
        public string Name { get; set; }

        /// <summary>监听端口</summary>
        [JsonProperty("port")]
        public int Port { get; set; }

        /// <summary>品牌标识（预留扩展）</summary>
        [JsonProperty("brand")]
        public string Brand { get; set; } = "fanuc";

        /// <summary>数据变化频率（秒）</summary>
        [JsonProperty("dataChangeInterval")]
        public int DataChangeInterval { get; set; } = 10;

        /// <summary>剧本模式：auto=自动循环 / manual=手动触发</summary>
        [JsonProperty("scenarioMode")]
        public string ScenarioMode { get; set; } = "auto";

        /// <summary>模拟设备列表</summary>
        [JsonProperty("devices")]
        public List<DeviceConfig> Devices { get; set; } = new List<DeviceConfig>();
    }

    /// <summary>单台模拟设备配置</summary>
    public class DeviceConfig
    {
        /// <summary>设备编码（需与cnc_machine.device_code一致）</summary>
        [JsonProperty("deviceCode")]
        public string DeviceCode { get; set; }

        /// <summary>设备描述</summary>
        [JsonProperty("desc")]
        public string Desc { get; set; }

        /// <summary>初始NC程序名</summary>
        [JsonProperty("initialProgram")]
        public string InitialProgram { get; set; } = "O0001";

        /// <summary>初始零件数</summary>
        [JsonProperty("initialPartCount")]
        public int InitialPartCount { get; set; } = 0;
    }
}
