export const ADMIN_SYSTEM_TAG_QUERY = {
  title: "ADMIN",
  locked: true,
  type: "system",
} as const

export type SystemAdminTagLike = {
  title?: string
  locked?: boolean
  type?: string
}

export type AdminTaggableUser = {
  tags?: string[]
}

export function isSystemAdminTag(
  tag: SystemAdminTagLike | null | undefined,
): boolean {
  if (!tag) return false
  return (
    tag.title === ADMIN_SYSTEM_TAG_QUERY.title &&
    tag.locked === ADMIN_SYSTEM_TAG_QUERY.locked &&
    tag.type === ADMIN_SYSTEM_TAG_QUERY.type
  )
}

export function userHasAdminTag(
  user: AdminTaggableUser | null | undefined,
  adminTag: { _id: string } | null | undefined,
): boolean {
  if (!user?.tags?.length || !adminTag?._id) return false
  return user.tags.includes(adminTag._id)
}
