import { stringify } from 'qs';
import { request } from 'umi';

//获取指定路线巡检结果
export async function getRecentAutoPatrolByRouteId(params) {
  return request(
    `/api/v1/patrol/auto/data/${params.projectId}?${stringify(params)}`,
  );
}
export async function getAutoPatrolByRouteId(params) {
  return request(`/api/v1/patrol/data/${params.projectId}/${params.routeId}`);
}
export async function getDumuDetail(detailId) {
  const res = await request(`/api/v1/dumu/detail/${detailId}`);
  return res;
}

export async function queryUserList(param) {
  return request(`/api/v1/user/project/${param.projectId}`);
}
export async function queryPatrol(params) {
  return request(
    `/api/v1/patrol/data/${params.projectId}?${stringify(params)}`,
  );
}

export async function queryAnalysisDict() {
  const res = await request(
    `/api/analysis/v1/analysis-dict/list?page_size=9999`,
    {
      method: 'POST',
    },
  );
  return { data: res?.data?.list };
}

export async function changeRecordStatus(params) {
  return request('/api/v1/patrol/record/item', {
    method: 'PUT',
    data: {
      ...params,
    },
  });
}

export async function getRouteList(params) {
  return request(`/api/v1/patrol/route-info/${params.ProjectId}`);
}

//获取指定路线巡检结果
export async function getPatrolRecordMandateInfo(params) {
  return request(`/api/v1/mandate/info?${stringify(params)}`);
}
export async function queryPatrolRecord(params) {
  return request(`/api/v1/patrol/record/${params.recordId}`);
}
export async function analysisResultList(params) {
  return request(`/api/v1/patrol/analysis-result?${stringify(params)}`);
}
export async function patrolRelationList(params) {
  return request(`/api/analysis/v1/patrol-relation/list`, {
    method: 'POST',
    data: params,
  });
}
export async function getPatrolDumuList(params) {
  return request(`/api/v1/dumu/patrol-list?${stringify(params)}`, {
    method: 'GET',
  });
}
export async function patrolOverview(params) {
  return request(`/api/v1/patrol/overview/${params.projectId}`);
}

export async function patrolOverviewLine(params) {
  return request(
    `/api/v1/patrol/chart-curve/${params.projectId}?${stringify(params)}`,
  );
}

export async function patrolOverviewPie(params) {
  return request(
    `/api/v1/patrol/chart-pie/${params.projectId}?${stringify(params)}`,
  );
}

/**
 * 获取系统自检相关任务id
 * @param {object} params
 * @param {number} params.project_id 项目id
 * @param {number} params.id 巡检id
 */
export async function getMandateIDs(params) {
  const res = await request(
    `/api/v1//patrol/relation-task?${stringify(params)}`,
  );
  return res?.data || [];
}
