using System;
using System.Collections.Generic;
using System.Net;
using System.Text;

namespace XYY.Core.Standard.Mvc
{
    /// <summary>
    /// 泛型对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ApiJsonModel<T>
    {
        /// <summary>
        /// 错误码(0表示无错误)
        /// </summary>
        public HttpStatusCode code { get; set; }
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool success { get; set; }
        /// <summary>
        /// 错误信息
        /// </summary>
        public string error { get; set; }
        /// <summary>
        /// 消息
        /// </summary>
        public string message { get; set; }
        /// <summary>
        /// Json数据
        /// </summary>
        public T data { get; set; }

        public string Guid
        {
            get; set;
        }

        public static ApiJsonModel<T> OK(T data)
        {
            return new ApiJsonModel<T>
            {
                code = HttpStatusCode.OK,
                data = data,
                success = true,
                message = "成功"                
            };
        }

        public static ApiJsonModel<T> Error(string message, T data)
        {
            return new ApiJsonModel<T>
            {
                code = HttpStatusCode.InternalServerError,
                data = data,
                success = false,
                message = message
            };
        }
    }



    [Serializable]
    public class ApiJsonModel : ApiJsonModel<object>
    {
        /// <summary>
        /// 错误码(0表示无错误)
        /// </summary>
        public HttpStatusCode code { get; set; }
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool success { get; set; }
        /// <summary>
        /// 错误信息
        /// </summary>
        public string error { get; set; }
        /// <summary>
        /// 消息
        /// </summary>
        public string message { get; set; }
        /// <summary>
        /// Json数据
        /// </summary>
        public object data { get; set; }


        public static ApiJsonModel OK(object data = null)
        {
            return new ApiJsonModel
            {
                code = HttpStatusCode.OK,
                data = data,
                success = true,
                message = "成功"
            };
        }

        public static ApiJsonModel Error(string message, object data = null)
        {
            return new ApiJsonModel
            {
                code = HttpStatusCode.InternalServerError,
                data = data,
                success = false,
                message = message
            };
        }
    }
}
