import { defHttp } from '/@/utils/http/axios';

import { BasicPageParams, BasicFetchResult } from '/@/api/model/baseModel';

export type PageParams<T> = BasicPageParams & T;

enum Api {
  pageList = '/service/manage_jp/project/list',
  saveOrUpdate = '/service/manage_jp/project/saveOrUpdate',
  del = '/service/manage_jp/project/del',
  allGps = '/service/manage_jp/projectScene/allSceneGps',
  getScene = '/service/manage_jp/project/getScene',
  addScene = '/service/manage_jp/project/addScene',
  delScene = '/service/manage_jp/project/delScene',
  createshare = '/service/manage_jp/projectScene/createSceneShare',
  shareGpsScene = '/service/manage_jp/projectScene/getSceneMap',
  listAllGps = '/service/manage_jp/projectScene/listSceneGps',
}

type listType = {};

export type MapOptType = {
  id?: number;
  projectName: string;
  projectSn: string;
  isShow: number;
  lat?: number | null;
  lon?: number | null;
  alt?: number;
};

export type MapSearchType = {
  searchKey: string;
  type?: number;
};

export type AddSceneParamType = {
  numList: string[];
  projectId: number;
};

export type ListGetResultModel = BasicFetchResult<listType>;
/**
 * @description: Get sample list value
 */

export const ListApi = (params: PageParams<{}>) =>
  defHttp.post<ListGetResultModel>({
    url: Api.pageList,
    params,
    data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const AddOptOrUpdateApi = (params: MapOptType) =>
  defHttp.post<any>({
    url: Api.saveOrUpdate,
    params,
    data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const DelMapOptApi = (params: Pick<MapOptType, 'id'>) =>
  defHttp.post<any>({
    url: Api.del,
    params,
    data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const AllGpsApi = (params: MapSearchType) =>
  defHttp.post<any>({
    url: Api.allGps,
    data: {
      ...params,
      type: Number(params.type),
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const ListAllGpsApi = (params: MapSearchType) =>
  defHttp.post<any>({
    url: Api.listAllGps,
    data: {
      ...params,
      // type: Number(params.type),
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const GetSceneListApi = (
  params: PageParams<{
    projectId: number;
  }>,
) =>
  defHttp.post<any>({
    url: Api.getScene,
    data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const AddSceneApi = (params: AddSceneParamType) =>
  defHttp.post<any>({
    url: Api.addScene,
    data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const DelSceneApi = (params: AddSceneParamType) =>
  defHttp.post<any>({
    url: Api.delScene,
    data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
//
export const CreateShareMapApi = (type: number, projectId: any, searchKey: any) => {
  // const url = projectId ? Api.createshare + `/${type}` : Api.createshare + `/${type}/${projectId}`;
  return defHttp.post<{
    ciphertext: string;
    type: number;
  }>({
    url: Api.createshare,
    data: { type, searchKey, projectId },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
};

export const GetShareMapApi = (params: { ciphertext: string; type: number }) =>
  defHttp.post<any>({
    url: Api.shareGpsScene,
    data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
