using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography.X509Certificates;

namespace WayneCloud.Models
{
    public enum TradeStatus
    {
        SUCCESS,
        PAYERROR,
        CANCELLING,
        CLOSED,
    }

    /// <summary>
    /// Host the 3rd party payment server processing result.
    /// </summary>
    public class ElectronicOrderProcessResultModel
    {
        public int Id { get; set; }

        [MaxLength(128)]
        public string BillNumber { get; set; }

        [Required]
        public string ResultCode { get; set; }
        public string ResultMessage { get; set; }
        public string ErrorDetail { get; set; }

        /// <summary>
        /// Gets or sets the raw result (a string) from 3rd party payment server.
        /// </summary>
        public string RawResult { get; set; }
    }

    public class FuelOrderDetailModel
    {
        public int Id { get; set; }
        public int PumpNumber { get; set; }
        public int NozzleNumber { get; set; }

        /// <summary>
        /// Gets or sets the fule product name this transaction consumed, like #93, #95, #DIESEL and etc.
        /// </summary>
        public string FuelProductName { get; set; }

        public string FuelProductId { get; set; }

        public decimal Qualtity { get; set; }

        public decimal Price { get; set; }

        public decimal Amount { get; set; }

        public string Category { get; set; }
    }

    /// <summary>
    /// Host the phase 1 supported transaction info.
    /// </summary>
    public class ElectronicOrderModel
    {
        [Key]
        public int Id { get; set; }
        [Required]
        [MaxLength(192)]
        public string SiteId { get; set; }

        //public string CurrentBuId { get; set; }
        //public string ConfigurationServiceUrl { get; set; }
        public Object Config { get; set; }
        public Object Certification { get; set;}
        /// <summary>
        /// Gets or sets the time that client side create this order
        /// </summary>
        public DateTime? CreationTime { get; set; }

        /// <summary>
        /// 根据不同场景选择不同的支付方式, accepted values: WX_SCAN、ALI_SCAN
        /// </summary>
        [Required]
        public string Channel { get; set; }

        [Required]
        public bool IsRefund { get; set; }

        /// <summary>
        ///  trade status, expected values: USERPAYING, SUCCESS, SUCCESS_CANCELLING, PAYERROR, PAYERROR_CANCELLING, CLOSED
        /// </summary>
        public TradeStatus TradeStatus { get; set; }

        /// <summary>
        /// Gets or sets the netamount for this transaction, this amount deducted all the discount, and should be the final amount would be charged from 
        /// customer account.
        /// </summary>
        [Required]
        public decimal NetAmount { get; set; }

        /// <summary>
        /// Gets or sets the grossamount for this transaction, this is not the final amount to be charged from 
        /// customer account, need substract the discount.
        /// </summary>
        public decimal GrossAmount { get; set; }

        public decimal TotalAmount { get; set; }
        /// <summary>
        /// Gets or sets the 商户订单号, 确保唯一
        /// </summary>
        [Required]
        [MaxLength(128)]
        public string BillNumber { get; set; }

        /// <summary>
        /// Gets or sets the 订单标题   UTF8编码格式，32个字节内，最长支持16个汉字
        /// </summary>
        [MaxLength(32)]
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets 用户授权码, 当商户用扫码枪扫用户的条形码时得到的字符串
        /// </summary>
        [Required]
        public string AuthCode { get; set; }

        /// <summary>
        /// Gets or sets the operator id for who submit this order from site.
        /// </summary>
        [MaxLength(128)]
        public string OperatorId { get; set; }

        /// <summary>
        /// Gets or sets the terminal id for submit this order
        /// </summary>
        [MaxLength(128)]
        public string TerminalId { get; set; }

        /// <summary>
        /// Gets or sets the time that server received this order for processing.
        /// </summary>
        public DateTime? ReceivedTime { get; set; }

        /// <summary>
        /// Gets or set the Optional data.
        /// sample:  {"key1":"value1","key2":"value2",...}
        /// 用户自定义的参数，将会在webhook通知中原样返回，该字段主要用于商户携带订单的自定义数据
        /// </summary>
        public PostPayQRCodeFuelOrderOptionalFieldModel Optional { get; set; }

        [Required(ErrorMessage = "Need provide at least one FuelOrderDetail")]
        public List<FuelOrderDetailModel> FuelOrderDetails { get; set; }

        /// <summary>
        /// Gets or sets the process result which from the communication result with the 3rd party payment server
        /// </summary>
        public List<ElectronicOrderProcessResultModel> ProcessResults { get; set; }

        public string ToSimpleLogString()
        {
            return "SiteId: " + this.SiteId + ", BillNumber: " + this.BillNumber;
        }
    }
    public class ALiPayCertification
    {
        public string Merchant_Private_Key { get; set; }
        public string Merchant_Public_Key { get; set; }
        public string Alipay_Public_key { get; set; }
    }
    public class PostPayQRCodeFuelOrderOptionalFieldModel
    {
        public int Id { get; set; }
        public string key1 { get; set; }
        public string value1 { get; set; }
        public string key2 { get; set; }
        public string value2 { get; set; }
        public string key3 { get; set; }
        public string value3 { get; set; }
        public string key4 { get; set; }
        public string value4 { get; set; }
        public string key5 { get; set; }
        public string value5 { get; set; }
        public string key6 { get; set; }
        public string value6 { get; set; }
        public string key7 { get; set; }
        public string value7 { get; set; }
        public string key8 { get; set; }
        public string value8 { get; set; }
        public string key9 { get; set; }
        public string value9 { get; set; }
        public string key10 { get; set; }
        public string value10 { get; set; }
        public string key11 { get; set; }
        public string value11 { get; set; }
        public string key12 { get; set; }
        public string value12 { get; set; }
        public string key13 { get; set; }
        public string value13 { get; set; }
        public string key14 { get; set; }
        public string value14 { get; set; }
        public string key15 { get; set; }
        public string value15 { get; set; }
    }
}