import { ResPage, TraceOrigin, Clause } from "@/api/interface/index";
import { PORT1 } from "@/api/config/servicePort";
import http from "@/api";

/**
 * @name 语料库-条文溯源
 */
// 获取列表
export const getTraceOriginList = (params: TraceOrigin.ReqTraceOriginParams) => {
  return http.get<ResPage<Clause.ClauseInfo>>(PORT1 + `/article/trace/list`, params);
};

// 获取词条相似度列表
export const getSimilarityListById = (params: TraceOrigin.ReqSimilarityParams) => {
  return http.post<TraceOrigin.ResSimilarityDataList[]>(PORT1 + `/article/trace/result/list`, params);
};

// 新增条文
export const addClause = (params: Partial<Clause.ClauseInfo>) => {
  return http.post(PORT1 + `/article/add`, params);
};

// 设置首见条文
export const setFirstClause = (params: { id: number }) => {
  return http.post(PORT1 + `/article/trace/firstArticle`, params);
};

// 关联首见条文
export const relativeFirstArticle = (params: { id: number; firstArticleId: number }) => {
  return http.post(PORT1 + `/article/trace/relativeFirstArticle`, params);
};

// 条文详情
export const getClauseDetail = (params: { id: number }) => {
  return http.get<Clause.ClauseInfo>(PORT1 + `/article/trace/detail`, params);
};

// 删除
export const deleteTraceOrigin = (params: { articleIds: number[] }) => {
  return http.post(PORT1 + `/article/trace/del`, params);
};

export const importTraceOrigin = (params: FormData) => {
  return http.post(PORT1 + `/article/import`, params, {
    headers: { "Content-Type": "multipart/form-data" },
    responseType: "blob"
  });
};
