import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { childProjectQuery, ProjectForm, ProjectQuery, ProjectVO } from '@/api/project/project/types';

/**
 * 查询项目列表
 * @param query
 * @returns {*}
 */

export const listProject = (query?: ProjectQuery): AxiosPromise<ProjectVO[]> => {
  return request({
    url: '/system/project/project/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询项目dxf
 * @param query
 * @returns {*}
 */

export const listDXFProject = (id: string | number): AxiosPromise<any> => {
  return request({
    url: '/system/project/projectFile/json/' + id,
    method: 'get'
  });
};

/**
 * 查询项目详细
 * @param id
 */
export const getProject = (id: string | number): AxiosPromise<ProjectVO> => {
  return request({
    url: '/system/project/project/' + id,
    method: 'get'
  });
};

/**
 * 新增项目
 * @param data
 */
export const addProject = (data: ProjectForm): AxiosPromise<string | number> => {
  return request({
    url: '/system/project/project',
    method: 'post',
    data: data
  });
};

/**
 * 修改项目
 * @param data
 */
export const updateProject = (data: ProjectForm) => {
  return request({
    url: '/system/project/project',
    method: 'put',
    data: data
  });
};

/**
 * 上传dxf文件
 * @param data
 */
export const upLoadProjectDXF = (data: any) => {
  return request({
    url: '/system/project/projectFile/upload/dxf',
    method: 'post',
    data: data
  });
};

/**
 * 通过GeoJson新增设施-光伏板
 * @param data
 */
export const addProjectFacilities = (data: any) => {
  return request({
    url: '/facility/photovoltaicPanel/geoJson',
    method: 'post',
    data: data,
    headers: {
      'X-No-Cache': 'true'
    }
  });
};

/**
 * 通过GeoJson新增设施-光伏板桩点、立柱、支架
 * @param data
 */
export const addProjectPilePoint = (data: any) => {
  console.log('🚀 ~ addProjectPilePoint ~ data:', data);

  return request({
    url: '/facility/photovoltaicPanelPoint/parts/geoJson',
    method: 'post',
    data: data
  });
};

/**
 * 通过GeoJson新增设施-方阵
 * @param data
 */
export const addProjectSquare = (data: any) => {
  return request({
    url: '/facility/matrix/geoJson',
    method: 'post',
    data: data
  });
};

/**
 * 通过GeoJson新增设施-箱变
 * @param data
 */
export const addBoxTransformer = (data: any) => {
  return request({
    url: '/facility/boxTransformer/geoJson',
    method: 'post',
    data: data
  });
};

/**
 * 通过GeoJson新增设施-逆变器
 * @param data
 */
export const addInverter = (data: any) => {
  return request({
    url: '/facility/inverter/geoJson',
    method: 'post',
    data: data
  });
};

/**
 * 删除项目
 * @param id
 */
export const delProject = (id: string | number | Array<string | number>) => {
  return request({
    url: '/system/project/project/' + id,
    method: 'delete'
  });
};

/**
 * 新增子项目
 * @param data
 */
export const addChildProject = (data: childProjectQuery) => {
  return request({
    url: '/system/project/project/sub',
    method: 'post',
    data: data
  });
};

/**
 * 查询项目下的子项目列表
 * @param id
 */
export const getChildProject = (id: string | number): AxiosPromise<childProjectQuery[]> => {
  return request({
    url: '/system/project/project/list/sub/' + id,
    method: 'get'
  });
};

/**
 * 上传项目文件
 * @param data
 */
export const uploadProjectFile = (data: any) => {
  return request({
    url: '/system/project/project/save/tender/file',
    method: 'put',
    data: data
  });
};

/**
 * 切换项目
 * @param id
 */
export const changeProject = (id: string | number) => {
  return request({
    url: '/system/project/project/changeProject/' + id,
    method: 'get'
  });
};
