using Edge.Core.Domain.FccNozzleInfo;
using Edge.Core.Domain.FccNozzleInfo.Input;
using Edge.Core.Domain.FccOilInfo;
using Edge.Core.Domain.FccOilInfo.Input;
using Edge.Core.Domain.FccOrderInfo;
using Edge.Core.Domain.FccTankInfo;
using Edge.Core.Domain.FccTankInfo.Input;
using HengshanPaymentTerminal.MessageEntity.Incoming;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace HengshanPaymentTerminal.Http.Request
{
    public class HttpRequest
    {
    }

    /// <summary>
    /// 发送油枪信息到云端数据对象
    /// </summary>
    public class SendNozzleInfo : HttpRequest
    {
        public SendNozzleInfo(long id,UploadNozzleInfoInput uploadNozzleInfoInput,FccTankInfo? fccTankInfo)
        {
            this.NozzleId = id;
            this.PumpId = uploadNozzleInfoInput.FuelPoint;
            this.InternalGunNumber = uploadNozzleInfoInput.InternalNum;
            this.ExternalGunNumber = uploadNozzleInfoInput.NozzleNum;
            this.TankID = fccTankInfo?.Id ?? 0;
            this.ProductId = fccTankInfo?.OilId ?? 0;
        }

        /// <summary>
        /// fcc油枪id
        /// </summary>
        public long NozzleId { get; set; }

        /// <summary>
        /// 加油点
        /// </summary>
        public int PumpId { get; set; }

        /// <summary>
        /// 内部枪号
        /// </summary>
        public int InternalGunNumber { get; set; }

        /// <summary>
        /// 外部枪号
        /// </summary>
        public int ExternalGunNumber { get; set; }

        /// <summary>
        /// fcc 油罐id
        /// </summary>
        public long TankID { get; set; }

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

    /// <summary>
    /// 更新油枪信息到云端数据对象
    /// </summary>
    public class UpdateNozzleInfo : HttpRequest
    {
        public UpdateNozzleInfo(long id, UploadNozzleInfoInput uploadNozzleInfoInput, FccTankInfo? fccTankInfo)
        {
            this.NozzleId = id;
            this.PumpId = uploadNozzleInfoInput.FuelPoint;
            this.InternalGunNumber = uploadNozzleInfoInput.InternalNum;
            this.ExternalGunNumber = uploadNozzleInfoInput.NozzleNum;
            this.TankID = fccTankInfo?.Id ?? 0;
            this.ProductId = fccTankInfo?.OilId ?? 0;
        }

        /// <summary>
        /// fcc油枪id
        /// </summary>
        public long NozzleId { get; set; }

        /// <summary>
        /// 加油点
        /// </summary>
        public int PumpId { get; set; }

        /// <summary>
        /// 内部枪号
        /// </summary>
        public int InternalGunNumber { get; set; }

        /// <summary>
        /// 外部枪号
        /// </summary>
        public int ExternalGunNumber { get; set; }

        /// <summary>
        /// fcc 油罐id
        /// </summary>
        public long TankID { get; set; }

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

    /// <summary>
    /// 删除油枪信息发送到云端数据对象
    /// </summary>
    public class DeleteNozzleInfo : HttpRequest
    {
        public DeleteNozzleInfo(FccNozzleInfo fccNozzleInfo)
        {
            this.NozzleId = fccNozzleInfo.Id;
            this.PumpId = fccNozzleInfo.FuelPoint;
            this.InternalGunNumber = fccNozzleInfo.InternalNum;
            this.ExternalGunNumber = fccNozzleInfo.ExternalNum;
            this.TankID = -1;
            this.ProductId = -1;
        }

        /// <summary>
        /// fcc油枪id
        /// </summary>
        public long NozzleId { get; set; }

        /// <summary>
        /// 加油点
        /// </summary>
        public int PumpId { get; set; }

        /// <summary>
        /// 内部枪号
        /// </summary>
        public int InternalGunNumber { get; set; }

        /// <summary>
        /// 外部枪号
        /// </summary>
        public int ExternalGunNumber { get; set; }

        /// <summary>
        /// fcc 油罐id
        /// </summary>
        public long TankID { get; set; }

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

    }

    /// <summary>
    /// 发送油罐信息给云端
    /// </summary>
    public class SendTankInfo:HttpRequest
    {
        public SendTankInfo(long id,AddTankInput addTankInput)
        {
            this.TankId = id;
            this.TankNumber = addTankInput.Number;
            this.TankCapacity = addTankInput.Capacity;
            this.ProductId = addTankInput.OilId;
            this.ProductName = addTankInput.OilName;
        }
        /// <summary>
        /// FCC油罐id
        /// </summary>
        public long TankId { get; set; }
        
        /// <summary>
        /// 油罐号
        /// </summary>
        public int TankNumber { get; set; }

        /// <summary>
        /// 油罐容量
        /// </summary>
        public decimal TankCapacity { get; set; }

        /// <summary>
        /// 油品名称
        /// </summary>
        public string? ProductName { get; set; }
        /// <summary>
        /// FCC油品id
        /// </summary>
        public long? ProductId { get; set; }
    }

    /// <summary>
    /// 更改油罐信息给云端
    /// </summary>
    public class UpdateTankInfo : HttpRequest
    {
        public UpdateTankInfo(long id, UpdateTankInput updateTankInput)
        {
            this.TankId = id;
            this.TankNumber = updateTankInput.Number;
            this.TankCapacity = updateTankInput.Capacity;
            this.ProductId = updateTankInput.OilId;
            this.ProductName = updateTankInput.OilName;
        }
        /// <summary>
        /// FCC油罐id
        /// </summary>
        public long TankId { get; set; }

        /// <summary>
        /// 油罐号
        /// </summary>
        public int TankNumber { get; set; }

        /// <summary>
        /// 油罐容量
        /// </summary>
        public decimal TankCapacity { get; set; }

        /// <summary>
        /// 油品名称
        /// </summary>
        public string? ProductName { get; set; }
        /// <summary>
        /// FCC油品id
        /// </summary>
        public long? ProductId { get; set; }
    }

    /// <summary>
    /// 删除油罐信息给云端
    /// </summary>
    public class DeleteTankInfo : HttpRequest
    {
        public DeleteTankInfo(FccTankInfo fccTankInfo)
        {
            this.TankId = fccTankInfo.Id;
            this.TankNumber = fccTankInfo.Number;
            this.TankCapacity = fccTankInfo.Capacity;
            this.ProductId = fccTankInfo.OilId;
            this.ProductName = fccTankInfo.OilName;
        }
        /// <summary>
        /// FCC油罐id
        /// </summary>
        public long TankId { get; set; }

        /// <summary>
        /// 油罐号
        /// </summary>
        public int TankNumber { get; set; }

        /// <summary>
        /// 油罐容量
        /// </summary>
        public decimal TankCapacity { get; set; }

        /// <summary>
        /// 油品名称
        /// </summary>
        public string? ProductName { get; set; }
        /// <summary>
        /// FCC油品id
        /// </summary>
        public long? ProductId { get; set; }
    }

    /// <summary>
    /// 上传油品信息到云端数据对象
    /// </summary>
    public class SendOilInfo : HttpRequest
    {
        public SendOilInfo(long id, OilInfoInput oilInfoInput)
        {
            this.ProductId = id;
            this.ProductName = oilInfoInput.Name;
            this.ProductCode = oilInfoInput.Code.ToString();
            this.ProductPrice = oilInfoInput.Price;
        }
        /// <summary>
        /// fcc 油品id
        /// </summary>
        public long ProductId { get; set; }

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

        /// <summary>
        /// 油品码
        /// </summary>
        public string ProductCode { get; set; }

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

    /// <summary>
    /// 更新油品信息到云端数据对象
    /// </summary>
    public class UpdateOilInfo : HttpRequest
    {
        public UpdateOilInfo(long id, OilInfoInput oilInfoInput)
        {
            this.ProductId = id;
            this.ProductName = oilInfoInput.Name;
            this.ProductCode = oilInfoInput.Code.ToString();
            this.ProductPrice = oilInfoInput.Price;
        }

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

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

        /// <summary>
        /// 油品码
        /// </summary>
        public string ProductCode { get; set; }

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

    /// <summary>
    /// 删除油品信息到云端数据对象
    /// </summary>
    public class DeleteOilInfo : HttpRequest
    {
        public DeleteOilInfo(FccOilInfo fccOilInfo)
        {
            this.ProductId = fccOilInfo.Id;
            this.ProductName = fccOilInfo.Name;
            this.ProductCode = fccOilInfo.Code.ToString();
            this.ProductPrice = fccOilInfo.Price;
        }

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

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

        /// <summary>
        /// 油品码
        /// </summary>
        public string ProductCode { get; set; }

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

    /// <summary>
    /// fcc 发送订单给云端数据对象
    /// </summary>
    public class CreateTransaction : HttpRequest
    {
        public CreateTransaction(FccOrderInfo fccOrderInfo) 
        {
            this.ExternalGunNumber = fccOrderInfo.NozzleNum;
            this.OriginalAmount = fccOrderInfo.Amount;
            this.ActualPaymentAmount = null;
            this.Qty = fccOrderInfo.Volume;
            this.FuelItemTransactionEndTime = fccOrderInfo.EndTime ?? DateTime.Now;
            this.TransactionTime = fccOrderInfo.PaymentTime;
            this.Product = fccOrderInfo.OilName;
            this.Price = fccOrderInfo.Price;
            this.TransactionNumber = fccOrderInfo.Ttc.ToString();
            this.MiniProgramID = null;
            this.PaymentMethod = null;
        }

        /// <summary>
        /// 油枪号
        /// </summary>
        public int ExternalGunNumber { 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>
        [JsonConverter(typeof(CustomDateTimeConverter))]
        public DateTime FuelItemTransactionEndTime { get; set; }

        /// <summary>
        /// 交易时间
        /// </summary>
        [JsonConverter(typeof(CustomDateTimeConverter))]
        public DateTime? TransactionTime { get; set; }

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

        public decimal Price { get; set; }

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


        /// <summary>
        /// 用户id
        /// </summary>
        public int? MiniProgramID { get; set; }

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

    /// <summary>
    /// 发送云端油枪状态数据对象
    /// </summary>
    public class SendNozzleStatu : HttpRequest
    {
        public SendNozzleStatu(long nozzleId,HeartBeatNozzleState heartBeatNozzleState) 
        {
            this.NozzleId = nozzleId;
            this.Status = heartBeatNozzleState.STATU;
        }
        /// <summary>
        /// 油枪号
        /// </summary>
        public long NozzleId { get; set; }

        /// <summary>
        /// 状态：01：不可用  02：关闭  03：空闲  04：呼叫  05：授权  06：开始加油  07：挂起开始加油  08：加油中  09：挂起加油
        /// </summary>
        public int Status { get; set; }
    }

    /// <summary>
    /// 发送授权结果
    /// </summary>
    public class SendAuthorizationResult : HttpRequest
    {
        /// <summary>
        /// 枪号
        /// </summary>
        public long NozzleId { get; set; }

        /// <summary>
        /// 流水号
        /// </summary>
        public string TransactionNumber { get; set; } = string.Empty;

        /// <summary>
        /// 结果 1:FCC 与油机断开连接；2：FCC 发送信息到油机，但超时未回复；3：授权失败；4：授权成功
        /// </summary>
        public OilMachineStatus OilMachineStatus { get; set; }
    }

    /// <summary>
    /// 发送取消授权结果
    /// </summary>
    public class SendUnAuthorizationResult : HttpRequest
    {
        /// <summary>
        /// 枪号
        /// </summary>
        public long NozzleId { get; set; }

        /// <summary>
        /// 流水号
        /// </summary>
        public string TransactionNumber { get; set; } = string.Empty;

        /// <summary>
        /// 结果 1:FCC 与油机断开连接；2：FCC 发送信息到油机，但超时未回复；3：授权失败；4：授权成功；5：未找到流水号
        /// </summary>
        public OilMachineStatus OilMachineStatus { get; set; }
    }

    public enum OilMachineStatus
    {
        /// <summary>
        /// FCC与油机断开连接。
        /// </summary>
        Disconnected = 1,

        /// <summary>
        /// FCC向油机发送授权，油机超时未回复。
        /// </summary>
        AuthorizationTimeout = 2,

        /// <summary>
        /// 操作失败。
        /// </summary>
        Failed = 3,

        /// <summary>
        /// 操作成功。
        /// </summary>
        Success = 4,
        /// <summary>
        /// 未找到交易流水号。
        /// </summary>
        TransactionNumberNotFound = 5
    }

    /// <summary>
    /// 云端发送订单完成信息后回复
    /// </summary>
    public class OnGetPaidInfo : HttpRequest
    {

        /// <summary>
        /// 订单id
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 结果
        /// </summary>
        public int Result { get; set; }
    }

    /// <summary>
    /// 云端发送订单退款后回复
    /// </summary>
    public class OnGetRefundInfo : HttpRequest
    {

        /// <summary>
        /// 订单id
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 结果
        /// </summary>
        public int Result { get; set; }
    }

    /// <summary>
    /// 定义DateTime转json格式
    /// </summary>
    public class CustomDateTimeConverter : IsoDateTimeConverter
    {
        public CustomDateTimeConverter()
        {
            DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
        }
    }
}
