using JiaZhiQuan.Common.Config;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;

namespace JiaZhiQuan.Common.YCTech {
    public class YCTechModel {
        public class YCTechBaseRequest<TData> {
            public YCTechBaseInfo BaseInfo { get; set; }
            public YCTechBaseResponse<TData> Response { get; set; }
            public YCTechBaseRequest(string requestUrl) {
                BaseInfo = new YCTechBaseInfo {
                    RequestUrl = requestUrl
                };
            }

            public async Task ExeRequest(HttpClient httpClient, ConfigFromDb config) {
                Response = await this.YCTechExeReqeust(config,httpClient);
            }
        }

        public class YCTechBaseInfo {
            public string Host { get; set; }
            public string RequestUrl { get; set; }
            //代理商id
            public string AgentId { get; set; }
            //代理商key
            public string SignKey { get; set; }
        }
        /// <summary>
        /// 直充下单接口
        /// </summary>
        public class YCTechSubmitOrderRequest : YCTechBaseRequest<YCTechSubmitOrderRespData> {
            /// <summary>
            /// 直充下单接口
            /// </summary>
            public YCTechSubmitOrderRequest() : base("/api/order/SubmitOrder") {
            }
            //接入方订单号
            public string OutOrderId { get; set; }
            //充值号码/帐号/卡号/微信openid
            public string Account { get; set; }
            //京东sign(非空参与签名) 可为空
            public string Jdsign { get; set; }
            //商品id
            public string ProductId { get; set; }
            //订单状态回调地址，为空则不回调
            public string CallbackUrl { get; set; }
            //时间戳,格式:yyyyMMddHHmmssSSS
            public string Timestamp { get; set; }
        }
        public class YCTechSubmitOrderRespData {
            //平台订单号
            public string OrderId { get; set; }
            //接入方订单号
            public string OutOrderId { get; set; }
            //成本
            public double Cost { get; set; }
        }
        
        public class YCTechQueryOrderRequest : YCTechBaseRequest<YCTechQueryOrderRespData> {
            /// <summary>
            /// 订单查询接口
            /// </summary>
            public YCTechQueryOrderRequest() : base("/api/order/QueryOrder") {
            }
            //平台订单号
            public string OrderId { get; set; }
            //接入方订单号
            public string OutOrderId { get; set; }
            //时间戳,格式:yyyyMMddHHmmssSSS
            public string Timestamp { get; set; }
        }

        public class YCTechQueryOrderRespData {
            //平台订单号
            public string OrderId { get; set; }
            //接入方订单号
            public string OutOrderId { get; set; }
            //订单状态
            //OrderStatus	说明
            //  0	待处理
            //  1	处理中
            //  2	充值成功
            //  3	充值失败
            //  其他  订单异常
            public string OrderStatus { get; set; }
            //订单描述，如果是话费或油卡，会返回透传信息
            public string OrderDesc { get; set; }
            //完成时间
            public string CompleteTime { get; set; }
        }
        
        public class YCTechYuERequest : YCTechBaseRequest<YCTechYuERespData> {
            /// <summary>
            /// 代理商余额查询接口
            /// </summary>
            public YCTechYuERequest() : base("/api/order/QueryAgentYuE") {
            }

            //时间戳,格式:yyyyMMddHHmmssSSS
            public string Timestamp { get; set; }
        }

        public class YCTechYuERespData {
            //剩余金额
            public double SurplusYuE { get; set; }
            //授信金额
            public double ShouXinJE { get; set; }
            //剩余授信金额
            public double SurplusShouXinJE { get; set; }
        }
        
        public class YCTechSyncProductRequest : YCTechBaseRequest<List<YCTechSyncProductRespData>> {
            /// <summary>
            /// 商品同步接口
            /// </summary>
            public YCTechSyncProductRequest() : base("/api/order/SyncProduct") {
            }
            //时间戳,格式:yyyyMMddHHmmssSSS
            public string Timestamp { get; set; }
        }

        public class YCTechSyncProductRespData {
            //产品id
            public long Id { get; set; }
            //产品名称
            public string ProductName { get; set; }
            //面额
            public string MianE { get; set; }
            //面值
            public double MianZhi { get; set; }
            //计价类型
            public string JiJiaLX { get; set; }
            //计价
            public double JiJia { get; set; }
            //售价
            public double ShouJia { get; set; }
        }

        public class YCTechBaseResponse<TData> {

            public string Code { get; set; }
            public string Msg { get; set; }
            public TData Data { get; set; }
            public bool Sucess { get; set; } = false;
            //原始结果。
            public string raw;
        }

        public class YCTechOrderCallBackModel {
            public string AgentId { get; set; }
            public string OrderId { get; set; }
            public string OutOrderId { get; set; }
            public string OrderStatus { get; set; }
            public string OrderDesc { get; set; }
            public DateTime CompleteTime { get; set; }
            public string Sign { get; set; }
        }
        public enum OrderStatus {
            订单失败=-1,
            未更新=0,
            订单成功=1
        }
    }
}
