namespace WebApi.Controllers.Dto;

public static class BaseResponseExtensions
{
    public static BaseResponse<T> Ok<T>(this T response)
    {
        return new BaseResponse<T>
        {
            Success = true,
            Data = response
        };
    }

    public static BaseResponse<T> Ok<T>(this T response, string message)
    {
        return new BaseResponse<T>
        {
            Success = true,
            Data = response,
            Message = message
        };
    }

    public static BaseResponse Ok(this string message)
    {
        return new BaseResponse
        {
            Success = true,
            Message = message
        };
    }

    public static BaseResponse<T> Fail<T>(this string message)
    {
        return new BaseResponse<T>
        {
            Success = false,
            Message = message
        };
    }

    public static BaseResponse Fail(this string message)
    {
        return new BaseResponse
        {
            Success = false,
            Message = message
        };
    }
}

public class BaseResponse
{
    /// <summary>
    /// 是否成功
    /// </summary>
    public bool Success { get; set; }

    /// <summary>
    /// 错误消息
    /// </summary>
    public string? Message { get; set; }

    public static BaseResponse Fail(string message)
    {
        return new BaseResponse
        {
            Success = false,
            Message = message
        };
    }

    public static BaseResponse Done()
    {
        return new BaseResponse
        {
            Success = true
        };
    }

    public static BaseResponse Done(string message)
    {
        return new BaseResponse
        {
            Success = true,
            Message = message
        };
    }
}

public class BaseResponse<T> : BaseResponse
{
    /// <summary>
    /// 返回数据
    /// </summary>
    public T? Data { get; set; }
    
    public new static BaseResponse<T> Fail(string message)
    {
        return new BaseResponse<T>
        {
            Success = false,
            Message = message
        };
    }

    public static BaseResponse<T> Done(T data)
    {
        return new BaseResponse<T>
        {
            Success = true,
            Data = data
        };
    }
}

