using System;
using System.Collections.Generic;
using DapperORM.Common.Enums;

namespace DapperORM.Common.Models
{
    /// <summary>
    /// 搜索实体
    /// </summary>
    public class SearchModel
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public SearchModel() { }

        /// <summary>
        /// 当前页
        /// </summary>
        private int _CurrentPage = 1;

        /// <summary>
        /// 当前页
        /// </summary>
        public int CurrentPage
        {
            get
            {
                return _CurrentPage <= 0 ? 1 : _CurrentPage;
            }
            set
            {
                _CurrentPage = value;
            }
        }

        /// <summary>
        /// 每页大小
        /// </summary>
        private int _PageSize = 10;

        /// <summary>
        /// 每页大小
        /// </summary>
        public int PageSize
        {
            get
            {
                return _PageSize <= 0 ? 10 : _PageSize;
            }
            set
            {
                _PageSize = value;
            }
        }

        /// <summary>
        /// 获取起始行
        /// </summary>
        /// <returns></returns>
        public int GetStartRow() => (CurrentPage - 1) * PageSize;

        /// <summary>
        /// 排序
        /// </summary>
        public Dictionary<string, SortType> Orders { get; set; }

        /// <summary>
        /// 查询条件
        /// </summary>
        public Dictionary<string, object> Filters { get; set; }
    }
}
