package com.example.demo.dto.request.exam;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;


@ApiModel(value = "BasePageRequest", description = "分页请求协议")
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class BasePageRequest<T>  {

    @ApiModelProperty(value = "开始页", notes = "默认第1页", example = "1", required = true, hidden = false)
    @Min(1)
    @NotNull(message = "start:不能为空")
    private Integer start = 1;

    @ApiModelProperty(value = "每页数据", notes = "默认一页10条", example = "10", required = true, hidden = false)
    @Min(1)
    @NotNull(message = "limit:不能为空")
    private Integer limit = 10;

    @ApiModelProperty(value = "API调用的业务参数", notes = "API调用的业务参数", required = false, hidden = false)
    private T data;

    /**
     * 功能描述：前端是从第1页开始算起。后端的分页查询是第0页算期。
     *
     * @return
     */
    @JsonIgnore
    public Integer getPage() {
        return start >= 1 ? start - 1 : start;
    }

}