package com.microservices.pms.repository.domain;

import com.microservices.common.core.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;

/**
 * @author otto
 */
@Data
@ApiModel("代码库搜索对象")
public class PmsRepositorySearchVo {
    @ApiModelProperty(value = "企业标识")
    @NotBlank
    private String enterpriseIdentifier;
    @ApiModelProperty(value = "项目排序（下拉列表请使用字典：GitLink项目排序规则（gitlink_project_sort_rule））")
    private String sortBy;
    @ApiModelProperty(value = "搜索关键字")
    private String search;
    @ApiModelProperty(value = "页码")
    private Long page;
    @ApiModelProperty(value = "每页数量")
    private Long limit;
    @ApiModelProperty(value = "是否导入成功")
    private Boolean actived;

    public String genQueryString() {
        StringBuilder stringBuilder = new StringBuilder("?");
        if (page == null) {
            page = 1L;
        }
        if (limit == null) {
            limit = 15L;
        }
        stringBuilder.append("page=").append(page);
        stringBuilder.append("&limit=").append(limit);
        if (StringUtils.isNotEmpty(sortBy)) {
            stringBuilder.append("&sort_by=").append(sortBy);
        }
        if (StringUtils.isNotEmpty(search)) {
            stringBuilder.append("&search=").append(search);
        }
        if (actived != null) {
            stringBuilder.append("&actived=").append(actived ? "true" : "false");
        }
        return stringBuilder.toString();
    }
}
