
import BaseService from '../base'
import { ChangeDepDTO, ChangeRoleDTO, GetRroupDTO, GetStaffInfoDTO, ResignDTO, UpdateStaffDTO, AddStaffDTO } from './service.dto'

export default class Staff extends BaseService {
  static instance: Staff
  static getInstance() {
    if (!Staff.instance) {
      Staff.instance = new Staff()
    }
    return Staff.instance
  }

  router = {
    addexcel: { path: '/v1/staff/add-staffs-by-excel', crediential: true, headers: [['content-type', 'multipart/form-data']] },
    changeDep: { path: '/v1/staff/change-dep', crediential: true },
    changeRole: { path: '/v1/staff/change-role', crediential: true },
    getGroup: { path: '/v1/staff/get-group', crediential: true },
    getInfo: { path: '/v1/staff/get-staff', crediential: true },
    resign: { path: '/v1/staff/resign', crediential: true },
    updateInfo: { path: '/v1/staff/update-staff-info', crediential: true },
    addMember: { path: '/v1/staff/add-staff', crediential: true }
  }
  // constructor() {
  //   super()
  // }
  async addExcel(data:File, entId: string, onUploadProgress: (e: ProgressEvent)=>any) {
    const fd = new FormData()
    fd.append('file_data', data)
    fd.append('entId', entId)
    return await this.useService(this.router.addexcel, fd, { onUploadProgress })
  }

  /**
   * 变更员工部门
   * @param {ChangeDepDTO} data {ChangeDepDTO}
   * @returns
   */
  async changeDep(data:ChangeDepDTO) {
    return await this.useService(this.router.changeDep, data)
  }

  /**
   * 设置取消管理员
   * @param {ChangeRoleDTO}} data {ChangeRoleDTO}
   * @returns
   */
  async changeRole(data:ChangeRoleDTO) {
    return await this.useService(this.router.changeRole, data)
  }

  /**
   * 查询员工加入的群
   * @param {GetRroupDTO}} data {GetRroupDTO}
   * @returns
   */
  async getRroup(data:GetRroupDTO) {
    return await this.useService(this.router.getGroup, data)
  }

  /**
   * 获取员工信息
   * @param {GetStaffInfoDTO}} data {GetRroupDTO}
   * @returns
   */
  async getInfo(data:GetStaffInfoDTO) {
    return await this.useService(this.router.getInfo, data)
  }

  /**
   * 办理离职人员
   * @param {ResignDTO} data {ResignDTO}
   * @returns
   */
  async resign(data:ResignDTO) {
    return await this.useService(this.router.resign, data)
  }

  /**
   * 更新员工信息
   * @param {UpdateStaffDTO} data {UpdateStaffDTO}
   * @returns
   */
  async updateInfo(data:UpdateStaffDTO) {
    return await this.useService(this.router.updateInfo, data)
  }

  /**
   * 添加员工
   * @param {AddStaffDTO} data {AddStaffDTO}
   * @returns
   */
  async addMember(data:AddStaffDTO) {
    return await this.useService(this.router.addMember, data)
  }
}

