import router from '@/router'
import { getStaffOnDutyStatus } from '@/service/StaffService'
import { eRole } from '@/types/roleType'
import { getUserMsg } from './userMsg'

export function authCheck(cb: Function) {
  if (getUserMsg()) cb()
  else {
    router.push({
      name: 'Login',
    })
  }
}

export async function chatAuthCheck(cb: Function, cb2?: Function) {
  const msg = getUserMsg()
  if (msg?.role === eRole.user) {
    cb();
  }
  else if (msg?.role === eRole.staff) {
    const ret = await getStaffOnDutyStatus()
    if (ret.code === 200 && ret.data) {
      console.log('cb');
      cb()
    } else {
      cb2 && cb2()
    }
  } else {
    cb2 && cb2()
  }
}
