using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FuelServer.Core.Entity;
using Newtonsoft.Json;

namespace Fuel.Core.Transactions.Dto
{
    public class UploadTransactions
    {
        /// <summary>
        /// 油枪
        /// </summary>
        public int NozzleId { get; set; }
        /// <summary>
        /// 实际加油金额
        /// </summary>
        public decimal? OriginalAmount { get; set; }
        /// <summary>
        /// 实际支付金额
        /// </summary>
        public decimal? ActualPaymentAmount { get; set; }
        /// <summary>
        /// 升数
        /// </summary>
        public decimal Qty { get; set; }
        /// <summary>
        /// 挂枪时间
        /// </summary>
        public DateTime? FuelItemTransactionEndTime { get; set; }
        /// <summary>
        /// 交易时间
        /// </summary>
        public DateTime? TransactionTime { get; set; }
        /// <summary>
        /// 油品
        /// </summary>
        public string Product { get; set; }
        /// <summary>
        /// 用户id
        /// </summary>
        public int MiniProgramID { get; set; }
        /// <summary>
        /// 订单流水号
        /// </summary>
        public string TransactionNumber { get; set; }
        /// <summary>
        /// 1预支付、2后支付 
        /// </summary>
        public int Type { get; set; }
        /// <summary>
        /// 支付方式
        /// </summary>
        public int PaymentMethod { get; set; }

        public transactions ToTransactions(UploadTransactions upload, Guid Buid, product product, nozzle nozzle)
        {
            return new transactions()
            {
                Buid = Buid,
                NozzleId = upload.NozzleId,
                ProductId = product.Id,
                ActualPaymentAmount = upload.ActualPaymentAmount,
                FuelItemTransactionEndTime = upload.FuelItemTransactionEndTime,
                OrderStatus = transactionsORDERSTATUS.Unpaid,
                OrderType = ToTransactionsOrderType(upload.Type),
                OriginalAmount = upload.ActualPaymentAmount,
                PaymentMethod = upload.PaymentMethod,
                ProductName = product.ProductName,
                Qty = upload.Qty,
                TransactionNumber = upload.TransactionNumber,
                TransactionTime = DateTime.Now
            };
        }
        public static transactionsORDERTYPE ToTransactionsOrderType(int value)
        {
            if (Enum.IsDefined(typeof(transactionsORDERTYPE), value))
            {
                return (transactionsORDERTYPE)value;
            }
            else
            {
                throw new ArgumentException("Invalid order type value.", nameof(value));
            }
        }
        public static transactionsORDERSTATUS ToTransactionsORDERSTATUS(int value)
        {
            if (Enum.IsDefined(typeof(transactionsORDERSTATUS), value))
            {
                return (transactionsORDERSTATUS)value;
            }
            else
            {
                throw new ArgumentException("Invalid order type value.", nameof(value));
            }
        }
    }
}
