using ServiceCenter.Redis;
using ServiceCenter.WebApi;
using WCS.WorkEngineering.WebApi.Models.AGV;
using WCS.WorkEngineering.WebApi.Models.AGV.Request;
using WCS.WorkEngineering.WebApi.Models.AGV.Response;
using WCS.WorkEngineering.Worlds.Logs;

namespace WCS.WorkEngineering.WebApi.Controllers
{
    public class IwmsSApi
    {
        private static string _IwmsUrl = null!;

        /// <summary>
        /// AGV地址
        /// </summary>
        public static string IwmsUrl
        {
            get
            {
                _IwmsUrl ??= RedisHub.Default.Check("IwmsUrl");
                if (string.IsNullOrEmpty(_IwmsUrl))
                {
                    throw new KnownException($"请在Redis配置IwmsUrl", LogLevelEnum.High);
                }
                return _IwmsUrl;
            }
        }

        public static zhongTianIntoStockResponse zhongTianIntoStock()
        {
            var res = APICaller.CallApi2<zhongTianIntoStockResponse>(IwmsUrl + "/databus/publish/zhongTianIntoStock", new zhongTianIntoStockRequest
            {

            });
            //if (res.code != AgvResponseCode.Success)
            //{
            //    throw new KnownException(res.message, LogLevelEnum.High);
            //}
            return res;
        }

        public static zhongTianOutStockResponse zhongTianOutStock()
        {
            var res = APICaller.CallApi2<zhongTianOutStockResponse>(IwmsUrl + "/databus/publish/zhongTianOutStock", new zhongTianOutStockRequest
            {
            });
            //if (res.code != AgvResponseCode.Success)
            //{
            //    throw new KnownException(res.message, LogLevelEnum.High);
            //}
            return res;
        }
    }
}
