using PlcSiemens.Core.Extension;
using ServiceCenter.Logs;
using WCS.Core;
using WCS.Entity.Protocol.BCR;
namespace WCS.WorkEngineering.Extensions
{
    /// 
    ///  BCR扩展
    /// 
    public class BCR : Device
    {
        /// 
        ///   BCR扩展
        /// 
        /// 
        /// 
        public BCR(Device device, World world) : base(device, world)
        {
        }
        /// 
        ///  获取BCR码
        /// 
        /// 
        public string GetBCRCode()
        {
            var barcode = Data.Content.Trim('\0');
            if (barcode.IsNullOrWhiteSpace()) throw new KnownException($"{Entity.Code}--扫码失败,内容为空", LogLevelEnum.High);
            return barcode;
        }
    }
    /// 
    ///  BCR83
    /// 
    public class BCR83 : Device
    {
        /// 
        ///   BCR扩展
        /// 
        /// 
        /// 
        public BCR83(Device device, World world) : base(device, world)
        {
        }
        /// 
        ///  获取BCR码
        /// 
        /// 
        public string GetBCRCode()
        {
            var barcode = Data.BcrCode.Trim('\0');
            if (barcode.IsNullOrWhiteSpace()) throw new KnownException($"{Entity.Code}--扫码失败,内容为空", LogLevelEnum.High);
            return barcode;
        }
    }
    /// 
    ///  BCR扩展
    /// 
    public static class BCRExtension
    {
        /// 
        ///  获取BCR码
        /// 
        /// 
        /// BCR对应站点设备号
        /// 
        public static string GetBCRCode(this List bc, string code)
        {
            code = "BCR" + code;
            var bcr = bc.FirstOrDefault(p => p.Entity.Code == code) ?? throw new KnownException($"未找到扫码器{code}", LogLevelEnum.High);
            return bcr.GetBCRCode();
        }
        ///// 
        /////  获取BCR83码集合
        ///// 
        ///// 
        ///// 
        //public static string GetBCRCodeList(this BCR83 bc)
        //{
        //}
    }
}