using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    /// <summary>
    /// NG箱子
    /// </summary>
    public class NGBox
    {
        static string MaxCntInNGBox = "MaxCntInNGBox";
        static string CurCntInNGBox = "CurCntInNGBox";
        InputEquip_Config Config;

        public NGBox(InputEquip_Config config)
        {
            Config = config;
        }
        /// <summary>
        /// 门禁信号
        /// </summary>
        /// <returns>true,门开</returns>
        bool doorLimitSig()
        {
            return IOManager.DIValue(IO_Type.NGDoor_Limit, Config.Id).Equals(IO_VALUE.LOW);
        }
        /// <summary>
        /// 最大容量
        /// </summary>
        int MaxCntInBox = Common.ConfigAppSettings.GetIntValue(MaxCntInNGBox, 15);
        /// <summary>
        /// 当前容量
        /// </summary>
        int CurCntInBox = Common.ConfigAppSettings.GetIntValue(CurCntInNGBox, 0);
        /// <summary>
        /// 是否可以放入
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>

        public bool CanPutIn(out string msg)
        {
            msg = "";
            if (doorLimitSig())
            {
                msg = "无法放料,NG门已开";
                return false;
            }
            if (CurCntInBox >= MaxCntInBox)
            {
                msg = $"无法放料,NG箱已到达最大数量{MaxCntInBox},请清理NG箱物料";
                return false;
            }
            return true;
        }
        public bool State(out string msg)
        {
            msg = $"【NG箱:{CurCntInBox}/{MaxCntInBox}】";
            return CurCntInBox < MaxCntInBox;
        }
        /// <summary>
        /// 清除NG数量
        /// </summary>
        public void ClearCnt()
        {
            CurCntInBox = 0;
            Common.ConfigAppSettings.SaveValue(CurCntInNGBox, CurCntInBox);
        }
        /// <summary>
        /// 放入NG箱信息
        /// </summary>
        /// <param name="inOutParam"></param>
        public void PutIn(InOutParam inOutParam = null)
        {
            CurCntInBox++;
            Common.ConfigAppSettings.SaveValue(CurCntInNGBox, CurCntInBox);
        }
    }
}