import { Access } from '@/constant'

const getters = {
  token (state) {
    return state.user.token
  },
  tenant (state) {
    return state.user.tenantKey
  },
  tenantId (state) {
    return state.user.tenantId
  },
  org (state) {
    return state.user.orgKey
  },
  userId (state) {
    return state.user.id
  },
  name (state) {
    return state.user.name
  },
  avatar (state) {
    return state.user.avatar
  },
  roles (state) {
    return state.user.roles
  },
  accesses (state) {
    return state.user.accesses
  },
  permissionRoutes (state) {
    return state.permission.routes
  },
  isSuperAdmin (state, getters) {
    return getters.accesses.has(Access.MANAGE_TENANTS)
  },
  isTenantAdmin (state, getters) {
    return getters.accesses.has(Access.MANAGE_TENANT)
  },
  isGroupAdmin (state, getters) {
    return getters.accesses.has(Access.MANAGE_GROUP)
  },
  isTopGroupAdmin (state, getters) {
    return getters.isGroupAdmin && getters.tenant === getters.org
  },
  isValid (state, getters) {
    return getters.token && (getters.tenant || getters.isSuperAdmin)
  }
}

export default getters
