using System.ComponentModel;
using Newtonsoft.Json;

namespace StandardScene.Signal.Model
{
    /// <summary>
    /// PLC 机构：一把 S7 连接 + 一块 DB。点位和地标在 <see cref="PlcStationDockModel"/>。
    /// </summary>
    [SignalTable("stations", "stations.json", "PLC机构", Order = 1)]
    [Category("PLC数据管理")]
    [DisplayName("PLC配置列表(机构名称不能重复)")]
    public class PlcStationModel
    {
        /// <summary>逻辑名，握手点机构名、Worker 线程名都用它。不能空、不能重复。</summary>
        [DisplayName("机构名称")]
        public string JgName { get; set; } = "";

        /// <summary>西门子 PLC IP。</summary>
        [DisplayName("机构IP")]
        public string Ip { get; set; } = "127.0.0.1";

        /// <summary>S7 端口。填 0 则用进程字段 PlcPort（默认 102）。</summary>
        [DisplayName("端口")]
        public int Port { get; set; } = 102;

        /// <summary>西门子系列。跟随进程则用信号交互进程的 PlcVersion。</summary>
        [DisplayName("PLC类型")]
        public SignalPlcType PlcType { get; set; } = SignalPlcType.跟随进程;

        /// <summary>DB 块号。工位 BOOL 与心跳都拼到这块 DB。</summary>
        [DisplayName("DB块号")]
        public int DbNumber { get; set; } = 100;

        /// <summary>心跳字节偏移。未填 HeartDb 时拼 DB{n}.DBX{HeartByte}.{HeartBit}。</summary>
        [DisplayName("心跳字节")]
        public int HeartByte { get; set; } = 32;

        /// <summary>心跳位，0～7。</summary>
        [DisplayName("心跳位")]
        public int HeartBit { get; set; }

        /// <summary>上线 / 单牵引下线 / 双牵引下线 / 等待通行，决定 AutoLeave 分支。</summary>
        [DisplayName("上下机构")]
        public SignalLineType LineType { get; set; } = SignalLineType.未知;

        /// <summary>旧配置读字节地址。有工位表后不再使用；无工位表时合成 default 工位。</summary>
        [Browsable(false)]
        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
        public string ReadDb { get; set; }

        /// <summary>旧配置写字节地址。</summary>
        [Browsable(false)]
        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
        public string WriteDb { get; set; }

        /// <summary>旧配置心跳位整段地址，优先于心跳字节/位。</summary>
        [Browsable(false)]
        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
        public string HeartDb { get; set; }

        [Browsable(false)]
        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
        public int JgInPointId { get; set; }

        [Browsable(false)]
        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
        public string JgInContains { get; set; }

        [Browsable(false)]
        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
        public int JgPointId { get; set; }

        [Browsable(false)]
        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
        public string JgContains { get; set; }
    }
}
