import request from '@/config/axios'

export interface DeptVO {
  id?: number
  name: string
  parentId: number
  status: number
  sort: number
  leaderUserId: number
  phone: string
  email: string
  factoryIds: string[]
  costCenterIds: string[]
  stockLocationIds: string[]
  createTime: Date
  type: string
}

// 查询部门（精简)列表
export const getSimpleDeptList = async (): Promise<DeptVO[]> => {
  return await request.get({ url: '/system/dept/simple-list' })
}

// 获取指定部门精简信息列表
export const specifiedSimpleDepts = async (deptId: number): Promise<DeptVO[]> => {
  return await request.get({ url: '/system/dept/specifiedSimpleDepts?deptId=' + deptId })
}

export const getTaskWellNames = async (deptId: number, wellName: string) => {
  return await request.get({
    url: `/rq/iot-project-task/taskTreeWellNames?companyId=${deptId}&wellName=${wellName}`
  })
}

// 查询当前用户所属的公司级部门列表 项目 日报
export const companyLevelDepts = async (): Promise<DeptVO[]> => {
  return await request.get({ url: '/system/dept/companyLevelDepts' })
}

// 获取公司层级的部门 及所有子部门
export const companyLevelChildrenDepts = async (): Promise<DeptVO[]> => {
  return await request.get({ url: '/system/dept/companyLevelChildrenDepts' })
}

// 查询部门列表
export const getDeptPage = async (params: PageParam) => {
  return await request.get({ url: '/system/dept/list', params })
}

// 查询部门详情
export const getDept = async (id: number) => {
  return await request.get({ url: '/system/dept/get?id=' + id })
}

// 新增部门
export const createDept = async (data: DeptVO) => {
  return await request.post({ url: '/system/dept/create', data: data })
}

// 修改部门
export const updateDept = async (params: DeptVO) => {
  return await request.put({ url: '/system/dept/update', data: params })
}

// 删除部门
export const deleteDept = async (id: number) => {
  return await request.delete({ url: '/system/dept/delete?id=' + id })
}
