using PlcSiemens.Core.Extension;
using WCS.Core;
using WCS.Entity.Protocol.BCR;
using WCS.WorkEngineering.Worlds.Logs;
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('\r');
            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 bs, string code)
        {
            code = "BCR" + code;
            var bcr = bs.FirstOrDefault(p => p.Entity.Code == code) ?? throw new KnownException($"未找到扫码器{code}", LogLevelEnum.High);
            return bcr.GetBCRCode();
        }
    }
}