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 validMatterName
    {
        /// <summary>
        /// 物资名称验证：物资名称包含钢筋，且业务类型不是销售出厂，不允许进行计量操作；
        /// 业务类型验证：非计量不允许进行上秤操作
        /// </summary>
        /// <param name="weight"></param>
        /// <returns></returns>
        public bool ValidMethod(PreTrackScale trackScale)
        {
            //001006011外销出厂-复磅(码头);001006002外销出厂计量;001006004外销退货计量
            if (trackScale!=null && !string.IsNullOrEmpty(trackScale.matterName))
            {
                if (trackScale.matterName.Equals("钢筋12mm-28mm,高线6.5mm-10mm,盘螺6mm-14mm") && !trackScale.meterTypeNo.Equals("001006002")
                    && !trackScale.meterTypeNo.Equals("001006011") && !trackScale.meterTypeNo.Equals("001006004"))
                {
                    PbCache.ResultMessage = "物资名称为【"+ trackScale.matterName + "】，且业务类型不是外销出厂或销售退货，不允许进行计量操作！";
                    return false;
                }

            }

            if (trackScale != null && !string.IsNullOrEmpty(trackScale.meterTypeName))
            {
                if (trackScale.meterTypeName.Contains("非计量"))
                {
                    PbCache.ResultMessage = "当前业务类型为[非计量]，不允许进行计量操作！";
                    return false;
                }               
            }
            return true;
        }

        /// <summary>
        /// 验证物资是否需要发运重量
        /// </summary>
        /// <param name="trackScale"></param>
        /// <returns></returns>
        public bool ValidEffectiveWeight(PreTrackScale trackScale)
        {
            //2022年1月7日 钢筋12mm-28mm,高线6.5mm-10mm,盘螺6mm-14mm添加发运重量的限制
            if (trackScale.matterName.Equals("钢筋12mm-28mm,高线6.5mm-10mm,盘螺6mm-14mm") && trackScale.effectiveWeight == 0)
            {
                PbCache.ResultMessage = "物资名称为【" + trackScale.matterName + "】，发运重量为【"+ trackScale.effectiveWeight + "】，不允许进行计量操作，请重新联系库房进行发运！";
                return false;
            }
            return true;
        }

            /// <summary>
            /// 验证是否为二次资源的物料
            /// </summary>
            /// <param name="trackScale"></param>
            /// <returns></returns>
        public bool ValidSecondResourcesMatter(PreTrackScale trackScale)
        {
            if (trackScale == null || !trackScale.meterTypeName.Contains("外销"))
            {
                return false;
            }
            if (trackScale != null && !string.IsNullOrEmpty(trackScale.matterName) && !string.IsNullOrEmpty(trackScale.matterNo))
            {
                MeterBaseMatterInfoService matterInfoService = new MeterBaseMatterInfoService();
                RESTfulResult<MeterBaseMatterInfo> result = matterInfoService.doQueryId(trackScale.matterNo);
                if (result.Succeed && result.Data!=null)
                {
                    if (result?.Data?.isSecondResources == "1")
                    {
                        return true;
                    }
                }
            }
            return false;
        }
    }
}
