using System;

namespace StandardScene.Charge
{
    /// <summary>
    /// 通讯报文数据模型
    /// </summary>
    public class CommunicationMessage
    {
        /// <summary>
        /// 报文ID（自动生成）
        /// </summary>
        public string MessageId { get; set; }

        /// <summary>
        /// 时间戳
        /// </summary>
        public DateTime Timestamp { get; set; }

        /// <summary>
        /// 方向（发送/接收）
        /// </summary>
        public MessageDirection Direction { get; set; }

        /// <summary>
        /// IP地址
        /// </summary>
        public string IpAddress { get; set; }

        /// <summary>
        /// 端口号
        /// </summary>
        public int Port { get; set; }

        /// <summary>
        /// 原始报文数据（十六进制字符串）
        /// </summary>
        public string RawData { get; set; }

        /// <summary>
        /// 报文长度（字节）
        /// </summary>
        public int Length { get; set; }
        /// <summary>
        /// 协议类型
        /// </summary>
        public string Type {  get; set; }

        /// <summary>
        /// 关联的充电桩ID（可选）
        /// </summary>
        public string StationId { get; set; }

        public CommunicationMessage()
        {
            MessageId = GenerateMessageId();
            Timestamp = DateTime.Now;
        }

        private static string GenerateMessageId()
        {
            return $"MSG{DateTime.Now:yyyyMMddHHmmssfff}{new Random().Next(100, 999)}";
        }

        public override string ToString()
        {
            return $"[{Timestamp:HH:mm:ss.fff}] {Direction} {IpAddress}:{Port} - {Length}字节";
        }
    }

    //解析后的数据

    /// <summary>
    /// 报文方向枚举
    /// </summary>
    public enum MessageDirection
    {
        /// <summary>
        /// 发送
        /// </summary>
        Send = 0,

        /// <summary>
        /// 接收
        /// </summary>
        Receive = 1
    }
}

