package com.microservices.zone.search.dto;

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

import java.io.Serializable;
import java.util.List;

/**
 * 全局搜索请求对象
 *
 * @author microservices
 */
@Data
@ApiModel("全局搜索请求对象")
public class GlobalSearchRequest implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 搜索关键词
     */
    @ApiModelProperty(value = "搜索关键词", required = true)
    private String keyword;

    /**
     * 搜索类型列表（zone_project, resource, member）
     * 为空则搜索所有类型
     */
    @ApiModelProperty(value = "搜索类型列表")
    private List<String> types;

    /**
     * 专区ID
     */
    @ApiModelProperty(value = "专区ID")
    private Long zoneId;

    /**
     * 页码
     */
    @ApiModelProperty(value = "页码")
    private Integer pageNum = 1;

    /**
     * 每页数量
     */
    @ApiModelProperty(value = "每页数量")
    private Integer pageSize = 20;


    @ApiModelProperty(value = "额外搜索参数（项目类型：projectTypeId,topic）")
    private JSONObject extraSearchParam;

    public String toProjectEsSearchString(String gitlinkSearchUrl, String gitlinkProjectIds, String topic) {
        String esSearchString= gitlinkSearchUrl +
                "/search" +
                "?" +
                "page=" + this.pageNum +
                "&size=" + this.pageSize +
                "&term=" + this.keyword +
                "&type=" + 1 +
                "&instanceIds=" + gitlinkProjectIds;
        if(StringUtils.isNotEmpty(topic)){
            esSearchString+="&topic=" + topic;
        }
        return esSearchString;
    }
}
