/*
 * @Author: wyd
 * @Date: 2024-02
 * @LastEditors: JiangChunMei
 * @LastEditTime: 2024-06-24 14:28:49
 * @Description: 全局api
 */
import type { ConfigItem } from '@/types/system'
import { http } from '@/utils/http'
import type { useInfoResult, userItem } from '@/types/login'

/**
 * @description: 获取全局配置
 * @return {*}
 */
export const getConfigAPI = () => {
  return http<ConfigItem>({
    method: 'GET',
    url: '/system/config/basic'
  })
}

/**
 * @description: 获取全部园区楼宇
 * @return {*}
 */
export const getParkWebAPI = () => {
  return http<ParkItem[]>({
    method: 'GET',
    url: '/space/park/web'
  })
}

/**
 * @description: 获取全部园区楼宇
 * @return {*}
 */
export const getParkAPI = () => {
  return http<ParkItem[]>({
    method: 'GET',
    url: '/space/park/select/all'
  })
}

/**
 * @description: 获取当前用户有权限的园区楼宇
 * @return {*}
 */
export const getParkFilterAPI = () => {
  return http<ParkItem[]>({
    method: 'GET',
    url: '/space/park/select'
  })
}

/**
 * @description: 获取当前用户的所属企业
 * @return {*}
 */
export const getEnterpriseAPI = () => {
  return http<enterpriseItem[]>({
    method: 'GET',
    url: '/enterprise/current/select'
  })
}

/**
 * @description: 获取用户信息
 * @param {*} data
 * @return {*}
 */
export const getUserInfoApi = () => {
  return http<useInfoResult>({
    method: 'GET',
    url: '/system/user/profile'
  })
}

/**
 * @description: 保存用户信息
 * @param {*} data
 * @return {*}
 */
export const saveUserInfoApi = (data: userItem) => {
  return http({
    method: 'PUT',
    url: '/system/user/profile',
    data
  })
}

/**
 * @description: 修改密码
 * @param {*} oldPassword 旧密码 newPassword新密码
 * @return {*}
 */
export const savePwdApi = (data: { oldPassword: string; newPassword: string }) => {
  return http({
    method: 'PUT',
    url: `/system/user/profile/updatePwd?oldPassword=${data.oldPassword}&newPassword=${data.newPassword}`,
    data
  })
}

/**
 * @description: 系统管理员+园区管理员分组下拉框
 * @param {*} data
 * @return {*}
 */
export const getAdministratorApi = (data: { parkIds: EmptyArrayType }) => {
  return http<EmptyObjectType[]>({
    method: 'GET',
    url: '/administrator/select',
    data
  })
}

/**
 * @description: 获取省市区
 * @return {*}
 */
export const getRegionApi = () => {
  return http<EmptyObjectType[]>({
    method: 'GET',
    url: '/system/region/list'
  })
}

/**
 * @description: 获取系统管理员树
 * @return {*}
 * @author: JiangChunMei
 */
export const getSystemUserApi = () => {
  return http<EmptyObjectType[]>({
    url: '/user/system',
    method: 'GET'
  })
}

/**
 * @description: 获取园区管理员树
 * @param {object} data
 * @return {*}
 * @author: JiangChunMei
 */
export const getParkUserApi = (data: { parkIds?: string[] }) => {
  return http<EmptyObjectType[]>({
    url: '/user/park',
    method: 'GET',
    data
  })
}

/**
 * @description: 获取系统角色树
 * @return {*}
 * @author: JiangChunMei
 */
export const getSystemRoleApi = () => {
  return http<EmptyObjectType[]>({
    url: '/system/role/admin/list',
    method: 'GET'
  })
}

/**
 * @description: 获取园区角色树
 * @param {object} data
 * @return {*}
 * @author: JiangChunMei
 */
export const getParkRoleApi = (data: { parkId?: string; parkIds?: string[] }) => {
  return http<EmptyObjectType[]>({
    url: '/role/park',
    method: 'GET',
    data
  })
}

/**
 * @description: 获取企业用户树
 * @param {object} data
 * @return {*}
 * @author: JiangChunMei
 */
export const getEnterpriseUserApi = (data: { status?: number; parkIds?: string[] }) => {
  return http<EmptyObjectType[]>({
    url: '/user/enterprise',
    method: 'GET',
    data
  })
}

export const getDepartmentApi = () => {
  return http<EmptyObjectType[]>({
    url: '/department/tree',
    method: 'GET'
  })
}

/**
 * @description: 自定义分类（无分页）
 * @param {*} data type 1新闻分类 2通知公告 18智慧旅游
 * @return {*}
 */
export function treeCategoryApi(data: { type: number }) {
  return http<EmptyObjectType[]>({
    url: '/operate/news/category/tree',
    method: 'GET',
    data
  })
}

/**
 * @description: 获取指定类型的数据字典
 * @param {*} dictType 类型
 * @return {*}
 */
export function getDictTypeApi(dictType: string) {
  return http<EmptyArrayType>({
    url: '/system/dict/data/type/' + dictType
  })
}

/**
 * @description: 查询OSS对象基于id串
 * @param {string} id
 * @return {*}
 * @author: JiangChunMei
 */
export const getListByIdsApi = (id: string | string[]) => {
  return http<EmptyArrayType>({
    url: '/system/oss/listByIds/' + id,
    method: 'GET'
  })
}
