namespace QYZH.InteractiveMagazine.Models.Dto;

/// <summary>
/// 通用分页查询类
/// </summary>
public class PageQueryModel
{
    /// <summary>
    ///当前页
    /// </summary>
    public int PageIndex { get; set; } = 1;

    /// <summary>
    ///每页条数
    /// </summary>
    public int PageSize { get; set; } = 10;

    /// <summary>
    /// 排序字段
    /// </summary>
    public string Sort { get; set; } = string.Empty;
    /// <summary>
    /// 排序类型,前端传入的是"ascending"，"descending"
    /// </summary>
    public string SortType { get; set; } = string.Empty;

    /// <summary>
    /// 关键字
    /// </summary>
    public string? KeyWord { get; set; }
}


/// <summary>
/// 分页查询泛型类
/// </summary>
/// <typeparam name="T">查询参数类型</typeparam>
public class PageQueryModel<T> : PageQueryModel where T : class, new()
{
    /// <summary>
    /// 查询参数
    /// </summary>
    public T Params { get; set; } = new T();

    public TP ConvertTo<TP>() where TP : class
    {
        if (Params != null)
        {
            return Params as TP;
        }
        return default;
    }

    public int Start => (PageIndex - 1) * PageSize + 1;

    public int End => PageIndex * PageSize;
}
