﻿using System.Runtime.CompilerServices;

namespace JLGames.RocketDriver.Games.RpgMaterial.Common
{
    /// <summary>
    /// This struct should not be used for calculations
    /// 本结构体不应该用于计算
    /// Notification only
    /// 仅限于通知提示
    /// </summary>
    public struct UserNotifyData
    {
        internal readonly int m_Type;
        internal readonly int m_Id;
        internal readonly int m_UId;
        internal int m_Num;
        internal int m_Offset;

        /// <summary>
        /// Type
        /// 类型
        /// </summary>
        public int Type => m_Type;

        /// <summary>
        /// Id
        /// </summary>
        public int Id => m_Id;

        /// <summary>
        /// UId
        /// </summary>
        public int UId => m_UId;

        /// <summary>
        /// Update value of Number
        /// 更新值
        /// </summary>
        public int Num => m_Num;

        /// <summary>
        /// Offset value
        /// 偏移值
        /// </summary>
        public int Offset => m_Offset;

        /// <summary>
        /// Absolute value of offset
        /// 偏移绝对值
        /// </summary>
        public int AbsOffset => m_Offset < 0 ? -m_Offset : m_Offset;

        public override string ToString()
        {
            return $"Notify{{Id={Id},Type={Type},Num={Num},Offset={Offset}}}";
        }

        public UserNotifyData(int type, int id, int uId, int num, int offset)
        {
            m_Type = type;
            m_Id = id;
            m_UId = uId;
            m_Num = num;
            m_Offset = offset;
        }

        [MethodImpl((MethodImplOptions) 256)]
        public static implicit operator DataNum(UserNotifyData v)
        {
            return new DataNum(v.Type, v.Id, v.UId, v.Num);
        }

        [MethodImpl((MethodImplOptions) 256)]
        public static implicit operator DataOffset(UserNotifyData v)
        {
            return new DataOffset(v.Type, v.Id, v.UId, v.Offset);
        }
    }
}