using System.Text.Json.Serialization;

namespace WmsMobileServe.ApiServe.Mobile.Vo;

/// <summary>
/// 移动端接口的响应基础返回类
/// </summary>
public class MobileApiResponse
{

    /// <summary>
    /// 响应码
    /// </summary>
    [JsonPropertyName("code")]
    public int? Code { get; set; }

    /// <summary>
    /// 响应消息
    /// </summary>
    [JsonPropertyName("message")]
    public string? Message { get; set; }

    /// <summary>
    /// 成功的响应
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    public static MobileApiResponse Success(string message = "SUCCESS") => new() { Code = 200, Message = message };

    /// <summary>
    /// 数据重复的响应
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    public static MobileApiResponse Repeat(string message = "DATA_REPEAT") => new() { Code = 201, Message = message };

    /// <summary>
    /// 失败的响应
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    public static MobileApiResponse Fail(string message = "ERROR") => new() { Code = 400, Message = message };

}

/// <summary>
/// 移动端接口的响应带数据返回类
/// </summary>
public class MobileApiResponse<T> : MobileApiResponse
{

    /// <summary>
    /// 返回数据
    /// </summary>
    [JsonPropertyName("data")]
    public T? Data { get; set; }

    /// <summary>
    /// 成功的响应
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    public static MobileApiResponse<T> Success(string message = "SUCCESS", T? data = default) => new() { Code = 200, Message = message, Data = data };

    /// <summary>
    /// 数据重复的响应
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    public static MobileApiResponse<T> Repeat(string message = "DATA_REPEAT", T? data = default) => new() { Code = 201, Message = message, Data = data };

    /// <summary>
    /// 失败的响应
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    public static MobileApiResponse<T> Fail(string message = "ERROR", T? data = default) => new() { Code = 400, Message = message, Data = data };

}
