# ===============================================
# GROUPS
# ===============================================

extend type Query {
  groups(
    filter: String
    orderBy: String
  ): [Group]

  groupById(
    id: UUID!
  ): Group
}

extend type Mutation {
  createGroup(
    name: String!
  ): GroupResponse

  updateGroup(
    id: UUID!
    name: String!
    redirectOnLogin: String!
    permissions: [String]!
    rules: [GroupRuleInput]!
  ): DefaultResponse

  deleteGroup(
    id: UUID!
  ): DefaultResponse

  assignUserToGroup(
    groupId: UUID!
    userId: UUID!
  ): DefaultResponse

  unassignUserFromGroup(
    groupId: UUID!
    userId: UUID!
  ): DefaultResponse
}

# -----------------------------------------------
# TYPES
# -----------------------------------------------

type GroupResponse {
  operation: Operation
  group: Group
}

type Group {
  id: UUID
  name: String
  isSystem: Boolean
  redirectOnLogin: String
  redirectOnFirstLogin: String
  redirectOnLogout: String
  permissions: [String]
  rules: [GroupRule]
  users(
    page: Int
    pageSize: Int
    orderBy: UserOrderBy
    orderByDirection: OrderByDirection
    # Filter by name / email
    filter: String
    ): [UserMinimal]
  userCount: Int
  createdAt: Date
  updatedAt: Date
}

type GroupRule {
  id: UUID
  name: String
  mode: GroupRuleMode
  match: GroupRuleMatch
  roles: [String]
  path: String
  locales: [String]
  sites: [UUID]
}

input GroupRuleInput {
  id: UUID!
  name: String!
  mode: GroupRuleMode!
  match: GroupRuleMatch!
  roles: [String]!
  path: String!
  locales: [String]!
  sites: [UUID]
}

enum GroupRuleMode {
  ALLOW
  DENY
  FORCEALLOW
}

enum GroupRuleMatch {
  START
  EXACT
  END
  REGEX
  TAG
  TAGALL
}
