namespace Tiobon.Core.Model;

/// <summary>
/// 服务层响应实体(泛型)
/// </summary>
public class ServiceResult<T>
{
    /// <summary>
    /// 状态码
    /// </summary>
    public int Status { get; set; } = 200;
    /// <summary>
    /// 操作是否成功
    /// </summary>
    public bool Success { get; set; } = false;
    /// <summary>
    /// 返回信息
    /// </summary>
    public string Message { get; set; } = "";
    /// <summary>
    /// 开发者信息
    /// </summary>
    public string MessageDev { get; set; }
    /// <summary>
    /// 返回数据集合
    /// </summary>
    public T Data { get; set; }
    public T result { get; set; }

    /// <summary>
    /// 返回成功
    /// </summary>
    /// <param name="message">消息</param>
    /// <returns></returns>
    public static ServiceResult<T> OprateSuccess(string message)
    {
        return OprateSuccess(true, message, default);
    }

    /// <summary>
    /// 返回成功
    /// </summary>
    /// <param name="message">消息</param>
    /// <param name="data">数据</param>
    /// <returns></returns>
    public static ServiceResult<T> OprateSuccess(string message, T data)
    {
        return OprateSuccess(true, message, data);
    }
    /// <summary>
    /// 返回失败
    /// </summary>
    /// <param name="message">消息</param>
    /// <returns></returns>
    public static ServiceResult<T> OprateFailed(string message)
    {
        return OprateSuccess(false, message, default);
    }
    /// <summary>
    /// 返回失败
    /// </summary>
    /// <param name="message">消息</param>
    /// <param name="data">数据</param>
    /// <returns></returns>
    public static ServiceResult<T> OprateFailed(string message, T data)
    {
        return OprateSuccess(false, message, data);
    }
    /// <summary>
    /// 返回消息
    /// </summary>
    /// <param name="success">失败/成功</param>
    /// <param name="message">消息</param>
    /// <param name="data">数据</param>
    /// <returns></returns>
    public static ServiceResult<T> OprateSuccess(bool success, string message, T data)
    {
        return new ServiceResult<T>() { Message = message, Data = data, Success = success };
    }
}

/// <summary>
/// 服务层响应实体
/// </summary>
public class ServiceResult
{
    /// <summary>
    /// 状态码
    /// </summary>
    public int Status { get; set; } = 200;
    /// <summary>
    /// 操作是否成功
    /// </summary>
    public bool Success { get; set; } = false;
    /// <summary>
    /// 返回信息
    /// </summary>
    public string Message { get; set; } = "";
    /// <summary>
    /// 返回数据集合
    /// </summary>
    public object Data { get; set; }

    /// <summary>
    /// 操作成功
    /// </summary>
    /// <param name="msg"></param>
    /// <returns></returns>
    public static ServiceResult OprateSuccess(string msg = "操作成功")
    {
        return new ServiceResult
        {
            Message = msg,
            Success = true,
            Data = null
        };
    }

    /// <summary>
    /// 操作失败
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="status"></param>
    /// <returns></returns>
    public static ServiceResult OprateFailed(string msg = "操作失败", int status = 500)
    {
        return new ServiceResult
        {
            Message = msg,
            Status = status,
            Data = null,
        };
    }
}

//public class ServicePageResult<T>
//{
//    /// <summary>
//    /// 状态码
//    /// </summary>
//    public int Status { get; set; } = 200;
//    /// <summary>
//    /// 操作是否成功
//    /// </summary>
//    public bool Success { get; set; } = true;
//    /// <summary>
//    /// 返回信息
//    /// </summary>
//    public string Message { get; set; } = null;
//    /// <summary>
//    /// 当前页标
//    /// </summary>
//    public int Page { get; set; } = 1;
//    /// <summary>
//    /// 总页数
//    /// </summary>
//    public int PageCount => (int)Math.Ceiling((decimal)TotalCount / PageSize);
//    /// <summary>
//    /// 数据总数
//    /// </summary>
//    public int TotalCount { get; set; } = 0;
//    /// <summary>
//    /// 每页大小
//    /// </summary>
//    public int PageSize { set; get; } = 20;
//    /// <summary>
//    /// 返回数据
//    /// </summary>
//    public List<T> Data { get; set; }

//    public ServicePageResult() { }

//    public ServicePageResult(int page, int totalCount, int pageSize, List<T> data)
//    {
//        this.Page = page;
//        this.TotalCount = totalCount;
//        PageSize = pageSize;
//        this.Data = data;
//    }

//    public PageModel<TOut> ConvertTo<TOut>()
//    {
//        return new PageModel<TOut>(Page, TotalCount, PageSize, default);
//    }


//    public PageModel<TOut> ConvertTo<TOut>(IMapper mapper)
//    {
//        var model = ConvertTo<TOut>();

//        if (Data != null)
//        {
//            model.data = mapper.Map<List<TOut>>(Data);
//        }

//        return model;
//    }


//    public PageModel<TOut> ConvertTo<TOut>(IMapper mapper, Action<IMappingOperationOptions> options)
//    {
//        var model = ConvertTo<TOut>();
//        if (Data != null)
//        {
//            model.data = mapper.Map<List<TOut>>(Data, options);
//        }

//        return model;

//    }

//}


public class DT_TableDataT<T>
{
    /// <summary>
    /// 返回数据
    /// </summary>
    public List<T> DT_TableDataT1 { get; set; } = new List<T>();

    public DT_TablePageInfoT DT_TablePageInfoT1 { get; set; } = new DT_TablePageInfoT();

    public JM_TableColumnT1 JM_TableColumnT1 { get; set; } = new JM_TableColumnT1();

}
public class DT_TablePageInfoT
{
    public int PageNum { get; set; }
    public int PageSize { get; set; }
    public int TotalCount { get; set; }

}

/// <summary>
/// 服务层分页响应实体(泛型)
/// </summary>
public class ServicePageResult<T>
{
    public int code { get; set; } = 0;
    public string type { get; set; } = "success";
    /// <summary>
    /// 操作是否成功
    /// </summary>
    public bool Success { get; set; } = true;
    /// <summary>
    /// 返回信息
    /// </summary>
    public string message { get; set; } = null;

    public DT_TableDataT<T> result { get; set; }

    public ServicePageResult(int page, int totalCount, int pageSize, List<T> data, string message = "查询成功！")
    {
        var result = new DT_TableDataT<T>();
        result.DT_TableDataT1 = data;
        result.DT_TablePageInfoT1.PageNum = page;
        result.DT_TablePageInfoT1.PageSize = pageSize;
        result.DT_TablePageInfoT1.TotalCount = totalCount;
        this.message = message;
        this.result = result;
    }
}