using Newtonsoft.Json.Linq;
using PTMedicalInsurance.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PTMedicalInsurance.Business
{
    abstract class AbstractProcess
    {
        protected CenterBusiness cBus = new CenterBusiness();
        protected HisMainBusiness hBus = new HisMainBusiness();
        protected HisIrisServices hIS = new HisIrisServices();
        protected MIIrisServices mIS = new MIIrisServices();
        protected InvokeHelper invoker = new InvokeHelper();

        protected string outParam = "";

        public JObject OrginalInput { set; get; }

        /// <summary>
        /// 使用原始参数
        /// </summary>
        public bool UseOrginal {
            get;set;
        }

        /// <summary>
        /// 返回成功信息
        /// </summary>
        /// <returns></returns>
        protected CallResult Success()
        {
            return Success("成功");
        }
        protected CallResult Success(string msg)
        {
            return new CallResult(0, msg, outParam);
        }

        /// <summary>
        /// 返回失败信息
        /// </summary>
        /// <param name="code"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        protected CallResult Error(int code, string errMsg)
        {
            return Exception(code, errMsg, outParam);
        }

        protected CallResult Exception(int code, string errMsg,string param)
        {
            outParam = JsonHelper.setExceptionJson(code, errMsg, param).ToString();
            return new CallResult(code, errMsg, outParam);
        }
        protected CallResult Exception(string errMsg, string param)
        {
            return Exception(-1, errMsg, param);
        }

        protected CallResult IrisReturn(string msg,JObject obj)
        {
            outParam = JsonHelper.setIrisReturnValue(0, msg, obj).ToString();
            return new CallResult(0, msg, outParam);
        }

        /// <summary>
        /// 返回失败信息
        /// </summary>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        protected CallResult Error(string errMsg)
        {
            return new CallResult(-1, errMsg, outParam);
        }

        /// <summary>
        /// 业务过程
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public abstract CallResult Process(JObject input);

    }
}
