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
{
    class IPUploadFeeCancelProcess : AbstractProcess
    {
        public override CallResult Process(JObject input)
        {
            string errMsg = "";
            //退结算会返一个新的ID
            string newSettleID = JsonHelper.getDestValue(input, "output.setlinfo.setl_id");
            //取消平台结算信息
            if (mIS.cancleSettlement(newSettleID, out outParam) != 0)
            {
                return Exception(-1, "中心结算取消成功，医保平台结算信息取消失败！", outParam);
            }

            //取消出院登记
            if (cBus.cancleRegister(TradeEnum.InpatientExitCancel, out outParam) != 0)
            {
                return Exception(0, "中心，医保平台及HIS结算信息取消成功，取消出院登记失败！请手工取消出院登记！", outParam);
            }


            //中心取消传送
            if (cBus.cancleFeeUpload(TradeEnum.InpatientFeeCancel, out errMsg) != 0)
            {
                //rtnResult = JsonHelper.setExceptionJson(-1, "取消中心费用", errMsg).ToString();
                //return rtnResult;
            }
            //云平台取消传送
            if (mIS.deleteFee(out errMsg) != 0)
            {
                //rtnResult = JsonHelper.setExceptionJson(-1, "删除医保平台费用", errMsg).ToString();
                //return rtnResult;
            }

            //取消HIS医保结算信息
            if (hIS.cancleSettlementInfo(input, out outParam) != 0)
            {
                return Exception(-1, "中心跟医保平台结算取消成功， 取消HIS结算信息失败！", outParam);
            }

            return IrisReturn("取消结算成功", null);
        }
    }
}
