using Edge.Core.Domain.FccOrderInfo;
using HengshanPaymentTerminal.Http.Response;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace HengshanPaymentTerminal.Mqtt.Request
{
    /// <summary>
    /// 云端 MQTT 数据对象
    /// </summary>
    public class MqttRequest
    {
        /// <summary>
        /// 类型
        /// </summary>
        public MQTT_TYPE type { get; set; }

        /// <summary>
        /// 数据
        /// </summary>
        public string data { get; set; }

    }

    /// <summary>
    /// 标识 MQTT 数据类型
    /// </summary>
    public enum MQTT_TYPE
    {
        /// <summary>
        /// 授权
        /// </summary>
        AUTHORIZATION = 1,

        /// <summary>
        /// 取消授权
        /// </summary>
        UNAUTHORIZATION = 2,

        /// <summary>
        /// 已支付发送订单信息
        /// </summary>
        PAID = 3,

        /// <summary>
        /// 退款发送订单信息
        /// </summary>
        REFUND = 4
    }

    /// <summary>
    /// 云端 Mqtt 发送授权请求数据对象
    /// </summary>
    public class MqttAuthorizationRequest
    {
        /// <summary>
        /// 订单唯一标识符
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 油站唯一标识符
        /// </summary>
        public Guid Buid { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public long MiniProgramID { get; set; }

        /// <summary>
        /// 枪号
        /// </summary>
        public long NozzleId { get; set; }

        /// <summary>
        /// 油品ID
        /// </summary>
        public long ProductId { get; set; }

        /// <summary>
        /// 实际支付金额
        /// </summary>
        public decimal? ActualPaymentAmount { get; set; }

        /// <summary>
        /// 授权时间
        /// </summary>
        public DateTime? AuthorizationTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string? CreateBy { get; set; }

        /// <summary>
        /// 订单创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 挂枪时间
        /// </summary>
        public DateTime? FuelItemTransactionEndTime { get; set; }

        /// <summary>
        /// 是否删除
        /// </summary>
        public sbyte? IsDeleted { get; set; } = 0;

        /// <summary>
        /// 订单状态
        /// </summary>
        public transactionsORDERSTATUS OrderStatus { get; set; }

        /// <summary>
        /// 订单类型
        /// </summary>
        public transactionsORDERTYPE OrderType { get; set; }

        /// <summary>
        /// 原金额
        /// </summary>
        public decimal OriginalAmount { get; set; }

        /// <summary>
        /// 支付方式
        /// </summary>
        public long? PaymentMethod { get; set; }

        /// <summary>
        /// 油品名称
        /// </summary>
        public string ProductName { get; set; }

        /// <summary>
        /// 原升数
        /// </summary>
        public decimal Qty { get; set; }

        /// <summary>
        /// 实际加油升数
        /// </summary>
        public decimal? OriginalQty { get; set; }

        /// <summary>
        /// 退款金额
        /// </summary>
        public decimal? RefundAmount { get; set; }

        /// <summary>
        /// 订单流水号
        /// </summary>
        public string TransactionNumber { get; set; }

        /// <summary>
        /// 交易时间
        /// </summary>
        public DateTime? TransactionTime { get; set; }

        /// <summary>
        /// 加密字符串，用于验证金额是否篡改
        /// </summary>
        public string secret { get; set; }

        /// <summary>
        /// 支付返回结果
        /// </summary>
        public string RawResult { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public string ErrorDetail { get; set; }

        /// <summary>
        /// 支付结果代码
        /// </summary>
        public string ResultCode { get; set; }

        /// <summary>
        /// 是否授权
        /// </summary>
        public AuthorizationStatus authorizationStatus { get; set; }

        /// <summary>
        /// 单价
        /// </summary>
        public decimal Price { get; set; }

        public FccOrderInfo ToComponent(DateTime authorizationTime)
        {
            return new FccOrderInfo()
            {
                AuthorizationTime = authorizationTime,
                PaymentTime = TransactionTime,
                NozzleNum = (int)NozzleId,
                OilName = ProductName,
                PaymentStatus = 1,
                PayType = (int?)PaymentMethod,
                CloundOrderId = Id,
                Amount = OriginalAmount,
                Volume = Qty,
                AmountPayable = ActualPaymentAmount,
                UploadState = 1,
                IsDelete = 0,
                Price = this.Price
                
            };
        }

    }

    /// <summary>
    /// 云端发送取消授权数据对象
    /// </summary>
    public class MqttUnAhorizationRequest
    {
        /// <summary>
        /// 订单唯一标识符
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 油站唯一标识符
        /// </summary>
        public Guid Buid { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public long MiniProgramID { get; set; }

        /// <summary>
        /// 枪号
        /// </summary>
        public long NozzleId { get; set; }

        /// <summary>
        /// 油品ID
        /// </summary>
        public long ProductId { get; set; }

        /// <summary>
        /// 实际支付金额
        /// </summary>
        public decimal? ActualPaymentAmount { get; set; }

        /// <summary>
        /// 授权时间
        /// </summary>
        public DateTime? AuthorizationTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string? CreateBy { get; set; }

        /// <summary>
        /// 订单创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 挂枪时间
        /// </summary>
        public DateTime? FuelItemTransactionEndTime { get; set; }

        /// <summary>
        /// 是否删除
        /// </summary>
        public sbyte? IsDeleted { get; set; } = 0;

        /// <summary>
        /// 订单状态
        /// </summary>
        public transactionsORDERSTATUS OrderStatus { get; set; }

        /// <summary>
        /// 订单类型
        /// </summary>
        public transactionsORDERTYPE OrderType { get; set; }

        /// <summary>
        /// 原金额
        /// </summary>
        public decimal OriginalAmount { get; set; }

        /// <summary>
        /// 支付方式
        /// </summary>
        public long? PaymentMethod { get; set; }

        /// <summary>
        /// 油品名称
        /// </summary>
        public string ProductName { get; set; }

        /// <summary>
        /// 原升数
        /// </summary>
        public decimal Qty { get; set; }

        /// <summary>
        /// 实际加油升数
        /// </summary>
        public decimal? OriginalQty { get; set; }

        /// <summary>
        /// 退款金额
        /// </summary>
        public decimal? RefundAmount { get; set; }

        /// <summary>
        /// 订单流水号
        /// </summary>
        public string TransactionNumber { get; set; }

        /// <summary>
        /// 交易时间
        /// </summary>
        public DateTime? TransactionTime { get; set; }

        /// <summary>
        /// 加密字符串，用于验证金额是否篡改
        /// </summary>
        public string secret { get; set; }

        /// <summary>
        /// 支付返回结果
        /// </summary>
        public string RawResult { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public string ErrorDetail { get; set; }

        /// <summary>
        /// 支付结果代码
        /// </summary>
        public string ResultCode { get; set; }

        /// <summary>
        /// 是否授权
        /// </summary>
        public AuthorizationStatus authorizationStatus { get; set; }

        /// <summary>
        /// 单价
        /// </summary>
        public decimal? Price { get; set; }

    }

    /// <summary>
    /// 云端发送订单已支付数据对象
    /// </summary>
    public class MqttPaidRequest : MqttRequest
    {
        /// <summary>
        /// 订单唯一标识符
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 油站唯一标识符
        /// </summary>
        public Guid Buid { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public long MiniProgramID { get; set; }

        /// <summary>
        /// 枪号
        /// </summary>
        public long NozzleId { get; set; }

        /// <summary>
        /// 油品ID
        /// </summary>
        public long ProductId { get; set; }

        /// <summary>
        /// 实际支付金额
        /// </summary>
        public decimal? ActualPaymentAmount { get; set; }

        /// <summary>
        /// 授权时间
        /// </summary>
        public DateTime? AuthorizationTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string? CreateBy { get; set; }

        /// <summary>
        /// 订单创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 挂枪时间
        /// </summary>
        public DateTime? FuelItemTransactionEndTime { get; set; }

        /// <summary>
        /// 是否删除
        /// </summary>
        public sbyte? IsDeleted { get; set; } = 0;

        /// <summary>
        /// 订单状态
        /// </summary>
        public transactionsORDERSTATUS OrderStatus { get; set; }

        /// <summary>
        /// 订单类型
        /// </summary>
        public transactionsORDERTYPE OrderType { get; set; }

        /// <summary>
        /// 原金额
        /// </summary>
        public decimal OriginalAmount { get; set; }

        /// <summary>
        /// 支付方式
        /// </summary>
        public long? PaymentMethod { get; set; }

        /// <summary>
        /// 油品名称
        /// </summary>
        public string ProductName { get; set; }

        /// <summary>
        /// 原升数
        /// </summary>
        public decimal Qty { get; set; }

        /// <summary>
        /// 实际加油升数
        /// </summary>
        public decimal? OriginalQty { get; set; }

        /// <summary>
        /// 退款金额
        /// </summary>
        public decimal? RefundAmount { get; set; }

        /// <summary>
        /// 订单流水号
        /// </summary>
        public string TransactionNumber { get; set; }

        /// <summary>
        /// 交易时间
        /// </summary>
        public DateTime? TransactionTime { get; set; }

        /// <summary>
        /// 加密字符串，用于验证金额是否篡改
        /// </summary>
        public string secret { get; set; }

        /// <summary>
        /// 支付返回结果
        /// </summary>
        public string RawResult { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public string ErrorDetail { get; set; }

        /// <summary>
        /// 支付结果代码
        /// </summary>
        public string ResultCode { get; set; }

        /// <summary>
        /// 是否授权
        /// </summary>
        public AuthorizationStatus authorizationStatus { get; set; }

        /// <summary>
        /// 单价
        /// </summary>
        public decimal? Price { get; set; }
    }

    /// <summary>
    /// 云端发送订单退款数据对象
    /// </summary>
    public class MqttRefundRequest : MqttRequest
    {
        /// <summary>
        /// 订单唯一标识符
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 油站唯一标识符
        /// </summary>
        public Guid Buid { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public long MiniProgramID { get; set; }

        /// <summary>
        /// 枪号
        /// </summary>
        public long NozzleId { get; set; }

        /// <summary>
        /// 油品ID
        /// </summary>
        public long ProductId { get; set; }

        /// <summary>
        /// 实际支付金额
        /// </summary>
        public decimal? ActualPaymentAmount { get; set; }

        /// <summary>
        /// 授权时间
        /// </summary>
        public DateTime? AuthorizationTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string? CreateBy { get; set; }

        /// <summary>
        /// 订单创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 挂枪时间
        /// </summary>
        public DateTime? FuelItemTransactionEndTime { get; set; }

        /// <summary>
        /// 是否删除
        /// </summary>
        public sbyte? IsDeleted { get; set; } = 0;

        /// <summary>
        /// 订单状态
        /// </summary>
        public transactionsORDERSTATUS OrderStatus { get; set; }

        /// <summary>
        /// 订单类型
        /// </summary>
        public transactionsORDERTYPE OrderType { get; set; }

        /// <summary>
        /// 原金额
        /// </summary>
        public decimal OriginalAmount { get; set; }

        /// <summary>
        /// 支付方式
        /// </summary>
        public long? PaymentMethod { get; set; }

        /// <summary>
        /// 油品名称
        /// </summary>
        public string ProductName { get; set; }

        /// <summary>
        /// 原升数
        /// </summary>
        public decimal Qty { get; set; }

        /// <summary>
        /// 实际加油升数
        /// </summary>
        public decimal? OriginalQty { get; set; }

        /// <summary>
        /// 退款金额
        /// </summary>
        public decimal? RefundAmount { get; set; }

        /// <summary>
        /// 订单流水号
        /// </summary>
        public string TransactionNumber { get; set; }

        /// <summary>
        /// 交易时间
        /// </summary>
        public DateTime? TransactionTime { get; set; }

        /// <summary>
        /// 加密字符串，用于验证金额是否篡改
        /// </summary>
        public string secret { get; set; }

        /// <summary>
        /// 支付返回结果
        /// </summary>
        public string RawResult { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public string ErrorDetail { get; set; }

        /// <summary>
        /// 支付结果代码
        /// </summary>
        public string ResultCode { get; set; }

        /// <summary>
        /// 是否授权
        /// </summary>
        public AuthorizationStatus authorizationStatus { get; set; }

        /// <summary>
        /// 单价
        /// </summary>
        public decimal? Price { get; set; }
    }
}
