﻿using System;
using UnityEngine;

namespace JLGames.RocketDriver.Games.RpgMaterial.Common
{
    [Serializable]
    public class MetaData
    {
        [Tooltip("Id")] [SerializeField] 
        protected int m_Id;
        [Tooltip("Name\n名称")] [SerializeField] 
        protected string m_Name;
        [Tooltip("Type\n类型")] [SerializeField] 
        protected int m_Type;
        [Tooltip("Number Limmit. Format:[min, max]\n数量限制.格式：[最小值，最大值]")] [SerializeField]
        protected int[] m_Limit;
        [Tooltip("Description\n描述")] [SerializeField]
        protected string m_Desc;

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

        /// <summary>
        /// Name
        /// 名称
        /// </summary>
        public string Name => m_Name;

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

        /// <summary>
        /// Min value (inclusive)
        /// 允许最小数量 (包含)
        /// </summary>
        public int LimitMin => m_Limit[0];

        /// <summary>
        /// Max value (inclusive)
        /// 允许最大数量 (包含)
        /// </summary>
        public int LimitMax => m_Limit[1];

        /// <summary>
        /// 描述
        /// </summary>
        public string Desc => m_Desc;

        public override string ToString()
        {
            return $"{{Id={Id},Type={Type},Name={Name},LimitMin={LimitMin},LimitMax={LimitMax}}}";
        }

        public MetaData()
        {
        }

        public MetaData(int id, string name, int type, int limitMin, int limitMax, string desc)
        {
            m_Id = id;
            m_Name = name;
            m_Type = type;
            m_Limit = new[] {limitMin, limitMax};
            m_Desc = desc;
        }

        /// <summary>
        /// Check if number is allowed
        /// 检查数量是否允许
        /// </summary>
        /// <param name="num"></param>
        /// <returns>-1: less than the minimum value, 1: greater than the maximum value, 0: allowed<br/></returns>
        /// <returns>-1：小于最小值，1：大于最大值，0：允许<br/></returns>
        public int CheckLimit(int num)
        {
            if (num < LimitMin) return -1;
            if (num > LimitMax) return 1;
            return 0;
        }
    }
}