package com.microservices.zone.project.domain;

import com.alibaba.fastjson2.JSONObject;
import com.microservices.zone.project.domain.ZoneProject;
import com.microservices.zone.project.domain.vo.ZoneProjectDataVo;
import com.microservices.zone.search.dto.GlobalSearchResult;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 * ZoneProject with full-text search score
 * 用于全局搜索结果，包含全文搜索相关度评分
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ZoneProjectWithScore extends ZoneProject implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 全文搜索相关度评分（来自 MySQL MATCH...AGAINST）
     */
    private Double searchScore;

    public GlobalSearchResult toGlobalSearchResult(ZoneProjectDataVo zoneProjectDataVo) {
        GlobalSearchResult result = new GlobalSearchResult();
        result.setType("zone_project");
        result.setId(this.getId());
        result.setTitle(this.getName());
        result.setContent(this.getFullName());
        result.setDeptId(this.getDeptId());
        result.setZoneId(this.getZoneId());
        result.setCreateTime(this.getCreateTime());

        if (zoneProjectDataVo != null) {
            result.setExtendData(zoneProjectDataVo.getProjectProperties());
        }

        // 使用数据库返回的实际搜索评分
        Double score = this.getSearchScore();
        if (score == null || score == 0.0) {
            score = 0.1; // LIKE 匹配的最小评分
        }
        result.setScore(score);
        return result;
    }
}
