// 智库概览信息
import request from "@/api/request.js";

// 智库列表
export function getThinkTankList() {
  return request({
    method: 'GET',
    url: `/api/thinkTankOverview/thinkTanks`,

  })
}

export function getAllThinkTankList(params) {
  return request({
    method: 'GET',
    url: '/api/thinkTankOverview/thinkTanks/page',
    params: params  
  })
}
//智库概览:获取智库发布
export function getNewReport() {
  return request({
    method: 'GET',
    url: `/api/thinkTankOverview/newReport`,

  })
}

// 风险信号
export function getThinkTankRiskSignal() {
  return request({
    method: 'GET',
    url: `/api/thinkTankOverview/riskSignal`,

  })
}

// 政策建议趋势分布
export function getThinkTankPolicyIndustryChange(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankOverview/policyIndustryChange/${params}`,

  })
}

// 政策建议领域分布
export function getThinkTankPolicyIndustry(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankOverview/policyIndustry/${params.year}`,
    params
  })
}

// 资金流向
export function getThinkTankDonation() {
  return request({
    method: 'GET',
    url: `/api/thinkTankOverview/donation`,

  })
}

//智库概览:获取智库研究热点
export function getThinkTankHot(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankOverview/research/hot/${params}`,

  })
}


// 行业领域字典列表
export function getHylyList() {
  return request({
    method: 'GET',
    url: `/api/billImpactAnalysis/industry/hylyList`,
  })
}


//获取智库报告
export function getThinkTankReport(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankOverview/report`,
    params: params
  })
}

// 智库概览：政策建议（资源库-政策建议）
export function getThinkTankOverviewPolicy(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankOverview/policy`,
    params
  })
}

/*********  智库信息 */
//智库百科:获取全局信息
export function getThinkTankSummary(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/summary/${params.id}`,

  })
}


//智库报告:获取智库报告类型
export function getThinkDynamicsReportType() {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/reportType`,
  })
}

//智库动态:获取智库报告
export function getThinkDynamicsReport(params) {
  const safe = params || {}
  // 兼容两种调用方式：
  // 1) { id, startDate, authorName, currentPage, pageSize, researchTypeIds, searchText, sortFun, years }
  // 2) { id, startDate, parmas: { authorName, currentPage, pageSize, researchTypeIds, searchText, sortFun, years } }
  const inner = safe.parmas && typeof safe.parmas === 'object' ? safe.parmas : {}
  const id = safe.id
  const startDate = safe.startDate

  const authorName = inner.authorName ?? safe.authorName ?? ''
  const currentPage = inner.currentPage ?? safe.currentPage ?? 1
  const pageSize = inner.pageSize ?? safe.pageSize ?? 10
  const researchTypeIds = inner.researchTypeIds ?? safe.researchTypeIds ?? ''
  const searchText = inner.searchText ?? safe.searchText ?? ''
  const sortFun = inner.sortFun ?? safe.sortFun ?? false
  const years = inner.years ?? safe.years ?? null

  const query = { currentPage, pageSize, sortFun }
  // 仅在有值时才传，避免后端按空值筛选
  if (authorName) query.authorName = authorName
  if (researchTypeIds) query.researchTypeIds = researchTypeIds
  if (searchText) query.searchText = searchText
  if (years !== null && years !== undefined && years !== '') query.years = years

  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/report/${id}/${startDate}`,
    params: query
  })
}

// 智库领域观点分析（流式）
// [POST] 8.140.26.4:10029/report-domain-view-analysis
export function postReportDomainViewAnalysis(data) {
  return request({
    method: 'POST',
    // 开发环境走 Vite 同源代理，避免浏览器跨域（见 vite.config.js：/intelligent-api -> 8.140.26.4:10029）
    url: '/intelligent-api/report-domain-view-analysis',
    data
  })
}


//提出建议领域分布
export function getThinkPolicyIndustry(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/policyIndustry/${params.id}/${params.year}`,
  })
}
//提出政策建议涉及部门分布
export function getPolicyAdviceDeptDistribution(params){
   return request({
    method: 'GET',
    url: `/api/thinkTankInfo/policyDepartment/${params.id}/${params.year}`,
  })
}

//获取相关政策领域分布
export function getThinkPolicyIndustryTotal(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/policyIndustryTotal/${params.id}/${params.year}`,
  })
}

//获取热门研究方向变化趋势
export function getThinkPolicyIndustryChange(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/policyIndustryChange/${params.id}/${params.year}`,
  })
}

//获取智库政策
export function getThinkPolicy(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/policy/${params.id}/${params.startDate}`,
    params
  })
}

//智库百科基本信息
export function getThinkTankInfoBasic(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/basic/${params}`,
  })
}

//获取全球分支机构
export function getThinkTankInfoBranch(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/branch/${params}`,
  })
}

//获取经费来源统计
export function getThinkTankFundsTotal(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/fundsTotal/${params}`,
  })
}
//获取经费来源
export function getThinkTankFundsSource(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/fundsSource/${params}`,
  })
}

//获取研究领域演变
export function getThinkTankResearchAreae(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/researchArea/${params}`,
  })
}

//获取核心研究人员
export function getThinkTankPerson(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankInfo/person/${params}`,
  })
}

//智库报告:获取报告全局信息
export const getThinkTankReportSummary = (params) => {
  return request(
    {
      method: 'GET',
      url: `/api/thinkTankReport/summary/${params}`,
    }
  );
}
//智库报告：获取相关报告
export const getThinkTankReportRelated = (params) => {
  return request(
    {
      method: 'GET',
      url: `/api/thinkTankReport/related/${params}`,
    }
  );
}

//获取报告原文
export const getThinkTankReportcontentUrl = (params) => {
  return request(
    {
      method: 'GET',
      url: `/api/thinkTankReport/contentUrl/${params}`,
    }
  );
}

//获取报告内容摘要
export function getThinkTankReportAbstract(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankReport/abstract/${params}`,
  })
}

//获取报告主要观点
export function getThinkTankReportContent(params) {
  const { id, currentPage, pageSize } = params
  return request({
    method: 'GET',
    url: `/api/thinkTankReport/content/${id}`,
    params: {
      currentPage,
      pageSize,
    }
  })
}

// 获取报告核心论点（支持关键字搜索）
export function getThinkTankReportViewpoint(params) {
  const { reportId, currentPage, pageSize, keyword = '', orgIds = '' } = params
  return request({
    method: 'GET',
    url: `/api/thinkTankReport/viewpoint/${reportId}`,
    params: {
      currentPage,
      pageSize,
      keyword,
      orgIds,
    }
  })
}

//获取涉及科技领域
export function getThinkTankReportIndustry(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankReport/industry/${'Rand_RRA3572-1'}`,
  })
}

//获取科技领域词云
export function getThinkTankReportIndustryCloud(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankReport/keyword/${params.id}`,
  })
}

//获取政策建议落实情况
export function getThinkTankReportPolicy(params) {
  return request({
    method: 'GET',
    url: `/api/thinkTankReport/policy/${params}`,
  })
}

//获取相关政策动态
export function getThinkTankReportPolicyAction(params) {
  const {
    reportId,
    currentPage,
    pageSize,
    keyword = "",
    orgIds = "",
    // 新增：按科技领域 / 标签过滤
    industryName = ""
  } = params;
  return request({
    method: 'GET',
    url: `/api/thinkTankReport/policyDetail/${reportId}`,
    params: {
      currentPage,
      pageSize,
      keyword,
      // 后端按标签过滤使用的字段
      industryName,
      orgIds,
    }
  })
}

//通用接口:获取新闻资讯智库模块
export function getThinkTankReportNews() {
  return request({
    method: 'GET',
    url: `/api/commonFeature/news/0102`,
  })
}

//获取人物动态 通用接口:获取社交媒体-智库模块
export function getThinkTankReportRemarks() {
  return request({
    method: 'GET',
    url: `/api/commonFeature/remarks/0102`,
  })
}
