import { defHttp } from '/@/utils/http/axios';
import qs from 'qs'
import {
  LoginParams,
  LoginResultModel,
  GetUserInfoModel,
  UserInfoModel,
  RefreshTokenParams,
  SmsLoginParams,
} from './model/userModel';

import type { ErrorMessageMode } from '/#/axios';
import { log } from 'console';

export interface BasicPageParams {
  page: number;
  pageSize: number;
}


enum Api {
  Login = '/callProvider',
}

const locationType = { gis: true };

/**
 * @description: user login api
 */
export function gisLoginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 获取目录管理列表
 */
export function getDirectoryTreeList(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 增加目录管理树节点
 */
export function addTreeNode(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 得到地图列表
 */
export function getMapListByPage(data) {
  data = qs.stringify(data)
  // const formData = new FormData();
  // Object.keys(data).forEach((key) => {
  //   if(key == 'args'){
  //     formData.append('args[]', data.args[0]);
  //     formData.append('args[]', data.args[1]);
  //   }else{
  //     formData.append(key, data[key]);
  //   }
  // });
  // console.log("canshui00000"+formData);
  
// debugger
  return defHttp.post(
    {
      ...locationType,
      url: Api.Login,
      data
    },
    {
      joinPrefix: false,//控制是否在请求路径中加入yt
    }
  );
}

// /**
//  * @description: 获取传感器列表
//  */
// export function ligongGetMonitorSensors(params: LoginParams, mode: ErrorMessageMode = 'modal') {
//   return defHttp.get<LoginResultModel>(
//     {
//       ...locationType,
//       url: Api.MonitorSensors,
//       params,
//     },
//     {
//       errorMessageMode: mode,
//       joinPrefix: false,
//     }
//   );
// }

// /**
//  * @description: 获取传感器曲线
//  */
// export function ligongGetMonitorChart(params: LoginParams, mode: ErrorMessageMode = 'modal') {
//   return defHttp.get<LoginResultModel>(
//     {
//       ...locationType,
//       url: Api.MonitorChart,
//       params,
//     },
//     {
//       errorMessageMode: mode,
//       joinPrefix: false,
//     }
//   );
// }

export function getMyInfo() {
  return defHttp.get<UserInfoModel>({ url: Api.GetMyInfo });
}
/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}
export async function SendLoginSmsCode(phoneNumber: string) {
  return await defHttp.post<boolean>({ url: Api.SendLoginSmsCode + phoneNumber });
}

export async function doLogout() {
  await defHttp.post(
    {
      url: Api.Logout,
    },
    {
      joinPrefix: false,
    }
  );
}
export function doRefreshToken(params: RefreshTokenParams) {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.RefreshToken,
      params,
    },
    {
      joinPrefix: false,
    }
  );
}
export function smsCodeLoginApi(params: SmsLoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.SmsCodeLogin,
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

// 密码重置验证码
export function passwordResetCode(mobile) {
  return defHttp.post({
    url: Api.ResetCode + mobile,
  });
}

// 重置密码
export function forgetPasswordApi(data) {
  return defHttp.post({
    url: Api.ResetPassword + data.phoneNumber,
    data,
  });
}

export const getUserToken = (id: string) => {
  return defHttp.get<Record<'token' | 'refreshToken', string>>({
    url: `/third/login/id/${id}`,
  });
};
