import request from '@/config/axios'

// 产线工位 VO
export interface OrganizationVO {
  id: number // 组织id
  name: string // 组织名称
  parentId: number // 父组织id
  sort: number // 显示顺序
  workerUserId: number // 负责人
  machineId: number // 对应机台id
  phone: string // 联系电话
  email: string // 邮箱
  isEnable: boolean // 是否启用
  status: string // 组织状态
  orgClass: string // 组织等级
  orgType: string // 组织类型
}

export type DeviceParameterAnalysisNodeVO = {
  id: number | string
  name: string
  orgClass?: string
  parentId?: number | string
  children?: DeviceParameterAnalysisNodeVO[]
  equipments?: {
    id: number | string
    name: string
    parameters?: {
      id: number | string
      name: string
      code?: string
      type?: string | null
      dataType?: string | null
      unit?: string | null
      ratio?: number | null
    }[]
  }[]
}

// 产线工位 API
export const OrganizationApi = {
  // 查询产线工位列表
  getOrganizationList: async () => {
    return await request.get({ url: `/mes/organization/list` })
  },
  getListOrgWorker: async (params) => {
    return await request.get({ url: `/mes/organization/listOrgWorker`, params })
  },

  // 查询产线工位详情
  getOrganization: async (id: number) => {
    return await request.get({ url: `/mes/organization/get?id=` + id })
  },

  // 新增产线工位
  createOrganization: async (data: OrganizationVO) => {
    return await request.post({ url: `/mes/organization/create`, data })
  },

  // 修改产线工位
  updateOrganization: async (data: OrganizationVO) => {
    return await request.put({ url: `/mes/organization/update`, data })
  },

  // 删除产线工位
  deleteOrganization: async (id: number) => {
    return await request.delete({ url: `/mes/organization/delete?id=` + id })
  },

  // 导出产线工位 Excel
  exportOrganization: async (params) => {
    return await request.download({ url: `/mes/organization/export-excel`, params })
  },

  deviceParameterAnalysis: async (params: { keyword?: string, showDevices?: number }) => {
    return await request.get({ url: `/mes/organization/deviceParameterAnalysis`, params })
  }
}
