package com.microservices.zone.project.domain.vo;

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

/**
 * @author otto
 */

@Data
@ApiModel("GitLink项目搜索对象")
public class GitLinkProjectSearchVo {
    @ApiModelProperty(value = "项目语言")
    private Long languageId;
    @ApiModelProperty(value = "项目排序")
    private String sortBy;
    @ApiModelProperty(value = "搜索关键字")
    private String search;
    @ApiModelProperty(value = "页码")
    private Long page;
    @ApiModelProperty(value = "每页数量")
    private Long limit;

    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 (languageId != null) {
            stringBuilder.append("&language_id=").append(languageId);
        }
        if (StringUtils.isNotEmpty(sortBy)) {
            stringBuilder.append("&sort_by=").append(sortBy);
        }
        if (StringUtils.isNotEmpty(search)) {
            stringBuilder.append("&search=").append(search);
        }
        return stringBuilder.toString();
    }
}
