using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using com.hnshituo.core.webapp.vo;

namespace MeterConditionLibrary
{
    /// <summary>
    /// 验证是否车卡绑定了，是的话是内倒车辆
    /// 用于验证是否可进行内倒计量
    /// </summary>
    public class validCarCard
    {
        public bool ValidMethod(InnerMeterInfo scale, out string ResultMessage, out bool isError)
        {
            ResultMessage = "";
            isError = false;

            //若计量员记录则不验证，则为true
            if (PbCache.isNotValid)
            {
                return true;
            }

            if (PbCache.ltCarCard == null || PbCache.ltCarCard.Count == 0)
            {
                ResultMessage = "车辆不允许内倒计量";
                PbCache.ResultMessage = "服务端异常，获取计量卡车辆配置信息失败";
                isError = true;
                return false;
            }
            else
            {
                List<MeterBaseCarCard> data = PbCache.ltCarCard.Where(s => s.carNo == scale.carNo).ToList();

                if (data == null || data.Count == 0)
                {
                    ResultMessage = "车辆不允许内倒计量";
                    PbCache.ResultMessage = string.Format("在计量卡车配置中未找到车辆[{0}]有效信息，不允许进行内倒计量，请点【语音求助】，联系司秤工处理！", scale.carNo);
                    isError = true;
                    return false;
                }
                else if (data.Count == 1)
                {
                    return true;
                }
                else
                {
                    ResultMessage = "车辆不允许内倒计量";
                    PbCache.ResultMessage = string.Format("在计量卡车配置中找到多条车辆[{0}]有效信息", scale.carNo); ;
                    isError = true;
                    return false;
                }
            }
        }
    }
}
