// 科研资助体系
import request from "@/api/request.js";


// 资助体系:来源机构列表
/**
 * @param {moduleId} 
 */
export function getFundSourceOrg() {
  return request({
    method: 'GET',
    url: `/api/fund/fundSourceOrg`,
  })
}


/**
 * 资助体系:最新资助项目
 */
export function getNewProject() {
  return request({
    method: "GET",
    url: `/api/fund/newProject`
  })
}


// 获取新闻资讯
/**
 * @param {moduleId} 
 */
export function getNews(moduleId = "0107") {
  return request({
    method: 'GET',
    url: `/api/commonFeature/news/${moduleId}`,
  })
}


/**
 * 社交媒体
 */
export function getSocialMediaInfo(moduleId = "0107") {
  return request({
    method: "GET",
    url: `/api/commonFeature/remarks/${moduleId}`
  })
}

// 获取风险信号
/**
 * @param {moduleId} 
 */
export function getRiskSignal(moduleId = "0107") {
  return request({
    method: 'GET',
    url: `/api/commonFeature/riskSignal/${moduleId}`,
  })
}


//资助体系v2.0:资助领域分布情况:资助经费
export function findFundField(params) {
  return request({
    method: 'GET',
    url: `/api/fund/countryFundsAreaList/${params.year}`,

  })
}

//资助体系v2.0:资助领域分布情况:资助项目

export function findCountryProjectAreaList(params) {
  return request({
    method: 'GET',
    url: `/api/fund/countryProjectAreaList/${params.year}`,

  })
}
//资助体系v2.0:资助经费变化情况:资助经费
export function getCountryFundingChange(params) {
  return request({
    method: 'GET',
    url: `/api/fund/countryFundingChange/${params.startDate}`
  })
}

//资助体系v2.0:资助经费变化情况:资助项目
export function getCountryFundProjectChange(params) {
  return request({
    method: 'GET',
    url: `/api/fund/countryFundProjectChange/${params.startDate}`
  })
}

//资助体系v2.0:机构资助领域情况
export function getOrgFundsArea(params) {
  return request({
    method: 'GET',
    url: `/api/fund/countryFundsArea/${params.year}`,
  })
}

//资助体系v2.0:项目资助强度分布
export function getOrgFundStrength(params) {
  return request({
    method: 'GET',
    url: `/api/fund/orgFundStrength/${params.year}`,
  })
}


//资助体系:来源机构列表
export function geFundSourceOrg() {
  return request({
    method: 'GET',
    url: `/api/fund/fundSourceOrg`,
  })
}

// 获取行业领域列表
export function getAreaType() {
  return request({
    method: 'GET',
    url: `/api/commonDict/areaType`,
  })
}

/**
 * 资助项目列表：领域、年份用逗号拼接为一个查询参数（arealist=1,2,3&yearlist=2025,2024）
 */
function normalizeProjectListQueryParams(params) {
  const next = { ...(params || {}) }
  if (Array.isArray(next.arealist)) {
    next.arealist = next.arealist.filter((v) => v !== undefined && v !== null && v !== "").join(",")
  }
  if (Array.isArray(next.yearlist)) {
    next.yearlist = next.yearlist.filter((v) => v !== undefined && v !== null && v !== "").join(",")
  }
  return next
}

//资助体系v2.0:资助项目列表分页
export function getProjectListNew(params) {
  return request({
    method: 'GET',
    url: `/api/fund/getProjectListNew`,
    params: normalizeProjectListQueryParams(params)
  })
}
