using ServiceCenter.Logs;
using ServiceCenter.Redis;
using WCS.Core;
using WCS.Entity.Protocol.Station;

namespace WCS.WorkEngineering.Extensions
{
    public class Station : Device<IStation520, IStation521, IStation523>
    {
        public Station(Device device, World world) : base(device, world)
        {
        }

        /// <summary>
        ///  入库站点是否被禁止
        /// </summary>
        /// <returns></returns>
        public void 入库站点是否被禁止()
        {
            var config = RedisHub.Default.Check("ForbidTubuEnter") ?? throw new Exception("请在Redis中配置入库口禁用");
            var configs = config.Split(",");
            if (configs.Contains(Entity.Code)) throw new KnownException("当前入库口已被禁用，请联系运维人员了解具体情况", LogLevelEnum.High);
        }

        /// <summary>
        ///  入库站点是否满足执行条件
        /// </summary>
        /// <returns></returns>
        public void 入库站点是否满足执行条件()
        {
            if (Data.VoucherNo != Data2.VoucherNo) throw new KnownException($"凭证号不一致,DB520:{Data.VoucherNo}-DB521:{Data2.VoucherNo}", LogLevelEnum.High);
            if (Data3.Status.HasFlag(StatusEunm.Run)) throw new KnownException("设备运行中", LogLevelEnum.Low);
            if (!Data3.Status.HasFlag(StatusEunm.PH_Status)) throw new KnownException("无光电", LogLevelEnum.Mid);
            if (Data3.Status.HasFlag(StatusEunm.PH_Status) && Data2.Request == 0) throw new KnownException("有光电无请求", LogLevelEnum.Mid);
            if (!Data3.Status.HasFlag(StatusEunm.PH_Status) && Data2.Request == 1) throw new KnownException("无光电有请求", LogLevelEnum.Mid);
        }
    }
}
