using ASHermed.AdminInterface.Api.ContractModel;
using ASHermed.SinoInterface.Api.ContractModel;
using ASHermed.SinoInterface.Api.ContractModel.Payment.Model;
using ASHermed.SinoInterface.Api.IRepository;
using ASHermed.SinoInterface.Repository.MySql;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASHermed.SinoInterface.Api.MySqlRepository
{

    public class OnlineRefundRepository : BaseRepositoryToASHermed_SinoInterface<Online_Refund>, IOnlineRefundRepository
    {
        public int CreateRefundOrder(Online_Refund order)
        {
            StringBuilder str = new StringBuilder();
            str.Append("insert into Online_Refund ");
            str.Append(@"(RefundNo,OrderNo,TradeNo,RefundTime,RefundFee,CreateTime,Operator,Remark) ");
            str.Append(" values ");
            str.Append(@"(@RefundNo,@OrderNo,@TradeNo,@RefundTime,@RefundFee,@CreateTime,@Operator,@Remark); ");
            var parms = new Dictionary<string, object>();
            parms.Add("@RefundNo", order.RefundNo);
            parms.Add("@OrderNo", order.OrderNo);
            parms.Add("@TradeNo", order.TradeNo);
            parms.Add("@RefundTime", order.RefundTime);
            parms.Add("@RefundFee", order.RefundFee);
            parms.Add("@CreateTime", order.CreateTime);
            parms.Add("@Operator", order.Operator);
            parms.Add("@Remark", order.Remark);

            var result = Execute(str.ToString(), parms);
            return result;
        }


        public int PerfRefundOrder(string refundNo, BizContent3 content)
        {
            StringBuilder str = new StringBuilder();
            str.Append("update Online_Refund set ");
            str.Append(@"TradeNo=@TradeNo, 
                        RefundTime=@RefundTime,
                        RefundFee=@RefundFee
                    where RefundNo=@RefundNo");
            var parms = new Dictionary<string, object>();
            parms.Add("@RefundNo", refundNo);
            parms.Add("@TradeNo", content.Trade_no);
            parms.Add("@RefundTime", content.Gmt_refund_pay);
            parms.Add("@RefundFee", content.Refund_fee);
            var result = Execute(str.ToString(), parms);
            return result;
        }

        public Online_Refund GetRefundOrder(string refundNo)
        {
            var selectSql = new StringBuilder();
            var parms = new Dictionary<string, object>();
            selectSql.Append(@"select * from Online_Refund 
                                where RefundNo = @RefundNo ");

            parms.Add("@RefundNo", refundNo);
            var result = Query<Online_Refund>(selectSql.ToString(), parms);
            return result?.FirstOrDefault();
        }

    }


}
