import request from "@/api/request.js";

// 获取人物全局信息
/**
 * @param {personId} 
 * @header token
 */
export function getCharacterGlobalInfo(params) {
    return request({
        method: 'GET',
        url: `/api/personHomepage/summaryInfo/${params.personId}`,
        params,
    })
}

// 获取人物基本信息
/**
 * @param {personId} 
 * @header token
 */
export function getCharacterBasicInfo(params) {
    return request({
        method: 'GET',
        url: `/api/personHomepage/basicInfo/${params.personId}`,
        params,
    })
}

// 科技人物详情，获取领域观点
/**
 * @param {areaId} 
 * @header token
 */
export function getCharacterFieldView(params) {
    return request({
        method: 'GET',
        url: `/api/personHomepage/areaOptions/${params.areaId}`,
        params,
    })
}

// 获取最新动态
/**
 * @param {personId,cRelated,currentPage,pageSize} 
 * @header token
 */
export function getCharacterLatestDynamic(params) {
    return request({
        method: 'GET',
        url: `/api/personHomepage/dynamics/${params.personId}`,
        params,
    })
}

// 获取人物成果报告
/**
 * @param {personId,industryId,currentPage,pageSize,year} 
 * @header token
 */
export function getCharacterAchievementReport(params) {
    return request({
        method: 'GET',
        url: `/api/personHomepage/findingsReport/${params.personId}/${params.year}`,
        params,
    })
}

// 获取人物历史提案
/**
 * @param {personId,industryId,currentPage,pageSize} 
 * @header token
 */
export function getCharacterProposal(params) {
    return request({
        method: 'GET',
        url: `/api/personHomepage/historyBill/${params.personId}`,
        params,
    })
}

// 获取履历
/**
 * @param {personId} 
 * @header token
 */
export function getCharacterResume(params) {
    return request({
        method: 'GET',
        url: `/api/personHomepage/jobResume/${params.personId}`,
        params,
    })
}

// 获取观点
/**
 * @param {personId,year} 
 * @header token
 */
export function getCharacterView(params) {
    return request({
        method: 'GET', 
        url: `/api/personHomepage/option/`,
        params,
    })
}

// 国会议员，获取资金来源
/**
 * @param {personId,year} 
 * @header token
 */
export function getCharacterFundSource(params) {
    return request({
        method: 'GET',
        url: `/api/personHomepage/personFunds/`,
        params,
    })
}

// 获取人物关系
/**
 * @param {personId} 
 * @header token
 */
export function getCharacterRelation(params) {
    return request({
        method: 'GET',
        url: `/api/personHomepage/personRelation/${params.personId}`,
        params,
    })
}
// 获取人物教育履历
/**
 * @param {personId} 
 * @header token
 */
export function getCharacterReducationResume(params) {
    return request({
        method: 'GET',
        url: `/api/personHomepage/educationResume/${params.personId}`,
        params,
    })
}

// 获取相关实体
/**
 * @param {personId,startTime} 
 * @header token
 */
export function getCharacterRelatedEntity(params) {
    return request({
        method: 'GET',
        url: `/api/personHomepage/personRelation/${params.personId}/${params.startTime}`,
        params,
    })
}
export function getareaType(params) {
    return request({
        method: 'GET',
        url: `/api/commonDict/areaType`,
        params
    })
}
 

export async function getFindingsReport(personId, params = {}) {
    const queryParts = []

    Object.entries(params).forEach(([key, value]) => {
        if (value === undefined || value === null || value === '') return
        if (Array.isArray(value)) {
            value.forEach(v => {
                queryParts.push(`${encodeURIComponent(key)}=${encodeURIComponent(v)}`)
            })
        } else {
            queryParts.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
        }
    })

    const queryString = queryParts.join('&')
    const url = queryString
        ? `/api/personHomepage/findingsReport/${personId}?${queryString}`
        : `/api/personHomepage/findingsReport/${personId}`

    return request(url, { method: 'GET' })
}

/**
 * 获取创新主体列表（大学/实验室/企业）
 * @param {Object} params - 请求参数
 * @param {string} params.arealist - 科技领域ID
 * @param {number} params.currentPage - 当前页码（从0开始）
 * @param {string} params.keywords - 搜索关键词
 * @param {number} params.pageSize - 每页条数
 * @param {string} params.subjectTypeId - 主体类型ID
 * @returns {Promise} 返回列表数据
 */
export async function getSubjectList(params) {
  return request('/api/innovateSubject/findListBySubjectTypeId', {
    method: 'GET',
    params
  })
} 
