using DeviceRepair.Models;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TsSFCDevice.Client.Biz.Base.Service;
using TsSFCDevice.Client.Biz.Base.Utils;

namespace TsSFCDevice.Client.Biz.Impl
{
    public class SFCRepository
    {
        private readonly Logger log;
        private static SFCRepository manager;

        private IDictionary<string, string> m_ApiParameters;
        /// <summary>
        /// API输入参数
        /// </summary>
        public IDictionary<string, string> ApiParameters
        {
            get
            {
                return m_ApiParameters;
            }
            set
            {
                m_ApiParameters = value;
            }
        }

        public static SFCRepository Instance
        {
            get
            {
                if (manager == null)
                    manager = new SFCRepository();
                return manager;
            }
        }

        public SFCRepository()
        {
            log = LogManager.GetCurrentClassLogger();
            m_ApiParameters = new Dictionary<string, string>();
        }

        internal string GetParameters(string cOperator = "", bool bFlag = true)
        {

            return ParametersObject.GetInstance(cOperator).GetJsonSerialized(m_ApiParameters);
        }

        /// <summary>
        /// 判断批次是否存在
        /// </summary>
        /// <param name="Batch"></param>
        /// <returns></returns>
        public bool GetBatchInfoToStaff(string Batch)
        {
            try
            {
                ApiParameters?.Clear();
                ApiParameters.Add("Batch", Batch);

                bool BatchExists = false;
                var Rtn = Utility.SfcBizService.CurrentSvc.Get_BatchInfoToStaff_Exists(GetParameters(),out  BatchExists);
                if (Rtn.Code != 1)
                {
                    throw new Exception(Rtn.Message);
                }
                return BatchExists; 
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                throw ex;
            }
        }
    }
}
