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

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

enum Api {
  Login = '/zhjc/sys/login',
  // DzdxInfo = '/yxBase/dzdxinfo/page',
  DzdxInfo = '/yxBase/largescreen/getDzInfoList',
  GcInfo = '/yxBase/gcbaseinfo/page',
  GcbBaseInfoPage = '/yxBase/gcbaseinfo/page',
  GetDzRiskTypeList = '/yxBase/largescreen/getDzRiskTypeList',
  GetDzRiskLevelList = '/yxBase/largescreen/getDzRiskLevelList',
  MapConfig = '/yxBase/dzsbsjjr/page',
  TJKJList = '/yxBase/largescreen/getTkjjcList',
  GetDzdxInfoTxData = '/yxBase/largescreen/getDzdxInfoTxData',
  updateDzdxInfo = '/yxBase/dzdxinfo',
  updateGcdxInfo = '/yxBase/gcbaseinfo',
  visualangle = '/yxBase/visualangle',
  getVisualangle = '/yxBase/visualangle/getInfo',
  videoprojection = '/yxBase/videoprojection',
}

const locationType = { isDebugger: true };

/**
 * @description: user login api
 */
export function ligongLoginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 获取视频投影
 */
export function getVideoprojection(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: `${Api.videoprojection}/${params.deviceId}`,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 新增视频投影
 */
export function videoprojection(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.videoprojection,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 获取视角
 */
export function getVisualangle(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  var user = JSON.parse(sessionStorage.getItem('user'));
  params.createdBy = user.userId;
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.getVisualangle,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 视角保存
 */
export function Visualangle(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.visualangle,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 跟新工程点信息
 */
export function UpdateGcdxInfo(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.put<LoginResultModel>(
    {
      ...locationType,
      url: Api.updateGcdxInfo,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 跟新地灾点信息
 */
export function UpdateDzdxInfo(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.put<LoginResultModel>(
    {
      ...locationType,
      url: Api.updateDzdxInfo,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 天基础，空基础
 */
export function TJKJList(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.TJKJList,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 获取变形体
 */
export function GetDzdxInfoTxData(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.GetDzdxInfoTxData,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 获取地图配置文件
 */
export function MapConfig(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.MapConfig,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 获取地灾风险等级数据
 */
export function GetDzRiskLevelList(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.GetDzRiskLevelList,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 获取地灾风险类型数据
 */
export function GetDzRiskTypeList(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.GetDzRiskTypeList,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 获取地灾点列表
 */
export function dzdxInfo(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.DzdxInfo,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 工程信息列表
 */
export function GcbBaseInfoPage(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.GcbBaseInfoPage,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 获取工程点列表
 */
export function gcInfo(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.GcInfo,
      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}`,
  });
};
