import request from '@/request'
import type * as TYPE from './types'

/**
 * 查询租户（小区列表）
 */
export const queryTenant = (params: {
  pageNo: number
  pageSize: number
  tenantName?: string
}): Promise<ResponseData<TYPE.queryTenantData>> => {
  return request.post('/tenant/query', params)
}

/**
 * 添加小区
 */
export const queryTenantAdd = (params: TYPE.TenantInfoAddParams): Promise<ResponseData<object>> => {
  return request.post('/tenant/add', params)
}

/**
 * 添加小区超管
 */
export const queryTenantAddAdmin = (params: {
  account: string
  password: string
  phone?: string
  roleId: string
  tenantId: string | number
  userName?: string
  userId?: string | number | null
}): Promise<ResponseData<object>> => {
  return request.post('/tenant/addAdmin', params)
}

/**
 * 查询小区超管
 */
export const queryTenantAdminInfo = (params: {
  tenantId: string | number
}): Promise<
  ResponseData<{
    account: string
    password: string
    userType: string
    phone: string
    userRole: {
      roleId: string
      roleName: string
    }
    userId: string
  }>
> => {
  return request.post('/tenant/queryAdmin', params)
}

/**
 * 查询小区详情信息
 */
export const queryTenantInfo = (params: {
  tenantId: string
}): Promise<ResponseData<TYPE.TenantInfoData[]>> => {
  return request.get('/tenant/queryTenantInfo', { params })
}

/**
 * 新增小区楼栋
 */
export const queryAddBuilding = (params: {
  tenantId: string
  buildingInfos: {
    tinfoName: string
    sort?: number
  }[]
}): Promise<ResponseData<object>> => {
  return request.post('/tenant/addBuilding', params)
}

/**
 * 新增小区楼层
 */
export const queryAddFloor = (params: {
  tenantId: string
  parentId: string
  floorInfos: {
    tinfoName: string
    sort?: number
  }[]
}): Promise<ResponseData<object>> => {
  return request.post('/tenant/addFloor', params)
}
