using Hncore.Infrastructure.Common;
using Hncore.Infrastructure.Extension;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace Hncore.Pass.PaymentCenter.Response.PaymentRecord
{
    public class QueryPaymentRecordByOrderIdResponse
    {
        public int ID { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime UpdateTime { get; set; }
        public int DeleteTag { get; set; }

        public int CreatorId { get; set; }


        public int UpdatorId { get; set; }
        public System.Int32 OwnerId { get; set; }
        /// <summary>
        /// 小区编号
        /// </summary>
        public int projectcode { get; set; }
        public System.DateTime RequestTime { get; set; }
        public System.String RequestParams { get; set; }
        public System.Int32 PaymentStatus { get; set; }
        public System.String PaymentNumber { get; set; }
        public System.String PaymentCompletionTime { get; set; }
        public System.Int32 PaymentTotal { get; set; }
        public System.Int32 PaymentType { get; set; }
        public System.Int32 CallbackNumber { get; set; }
        public System.String CallbackUrl { get; set; }

        public System.String Openid { get; set; }
        public System.String Appid { get; set; }

        public System.String Appname { get; set; }
        public System.String Body { get; set; }

        public System.String OrderId { get; set; }

        public System.Int32 BusinessType { get; set; }

        /// <summary>
        /// 订单类型
        /// </summary>
        public int orderType { get; set; }
        /// <summary>
        /// 来源Pos
        /// </summary>
        public int fromPos { get; set; }
        /// <summary>
        /// 回调任务状态
        /// </summary>
        public int CallbackStatus { get; set; }
        /// <summary>
        /// 支付渠道
        /// </summary>
        public int paymentChannel { get; set; }
        
        /// <summary>
        /// 物业名称
        /// </summary>
        public string PropertyName { get; set; }

        /// <summary>
        /// 根据orderid查询一条支付记录
        /// </summary>
        /// <param name="paymentRecordQuery"></param>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public static async Task<QueryPaymentRecordByOrderIdResponse> Query(IQueryable<Domain.PaymentRecord> paymentRecordQuery           
            , string orderId)
        {
            var paymentRecord = await paymentRecordQuery
                .OrderByDescending(t=>t.Id)
                .FirstOrDefaultAsync(t => t.OrderId == orderId);            
            CheckHelper.NotNull(paymentRecord,"支付记录不存在");    

            return paymentRecord.MapTo<QueryPaymentRecordByOrderIdResponse>();
        }
    }
}