
using Alipay.EasySDK.Kernel;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;

using System.Runtime.Serialization;

using XLib.DotNetCore.Base;

namespace HuanMeng.DotNetCore.Base
{
    /// <summary>
    /// 接口和服务调用基础响应类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [DataContract]
    [Serializable]
    public class BaseResponse<T> : IResponse
    {

        ///// <summary>
        ///// Http状态码
        ///// </summary>
        //[DataMember]
        //public HttpStatusCode StatusCode { get; set; }

        /// <summary>
        /// 功能执行返回代码
        /// </summary>
        [DataMember]
        public int Code { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        [DataMember]
        public string Message { get; set; }

        /// <summary>
        /// 数据
        /// </summary>
        [DataMember]
        public T? Data { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public BaseResponse()
        {
            //StatusCode = HttpStatusCode.OK;
            Code = 0;
            Message = "";
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        public BaseResponse(int code, string message)
        {
            Code = code;
            Message = message;
            Data = default(T);

        }


        /// <summary>
        /// 构造函数
        /// </summary>
        public BaseResponse(int code, string message = "", T? data = default(T))
        {
            Code = code;
            Message = message;
            Data = data;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public BaseResponse(ResponseCode code, string message = "", T? data = default(T))
        {
            Code = (int)code;
            Message = message;
            Data = data;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            return JsonConvert.SerializeObject(this, settings);
        }

    }
}
