# ===============================================
# TREE
# ===============================================

extend type Query {
  """
  Browse the tree.
  Must provide either `parentId` or a combination of `parentPath` and `locale`.
  """
  tree(
    siteId: UUID!
    parentId: UUID
    parentPath: String
    locale: String
    types: [TreeItemType]
    limit: Int
    offset: Int
    orderBy: TreeOrderBy
    orderByDirection: OrderByDirection
    """
    How many levels of children to include. Defaults to 1.
    """
    depth: Int
    """
    Include all parent folders up to root
    """
    includeAncestors: Boolean
    """
    Include all folders at root level
    """
    includeRootFolders: Boolean
    ): [TreeItem]
  folderById(
    id: UUID!
  ): TreeItemFolder
  folderByPath(
    siteId: UUID!
    locale: String!
    path: String!
  ): TreeItemFolder
}

extend type Mutation {
  createFolder(
    siteId: UUID!
    locale: String!
    parentId: UUID
    parentPath: String
    pathName: String!
    title: String!
  ): DefaultResponse
  deleteFolder(
    folderId: UUID!
  ): DefaultResponse
  duplicateFolder(
    folderId: UUID!
    targetParentId: UUID
    targetPathName: String!
    targetTitle: String!
  ): DefaultResponse
  moveFolder(
    folderId: UUID!
    targetParentId: UUID
  ): DefaultResponse
  renameFolder(
    folderId: UUID!
    pathName: String!
    title: String!
  ): DefaultResponse
}

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

enum TreeItemType {
  asset
  folder
  page
}

enum TreeOrderBy {
  createdAt
  fileName
  title
  updatedAt
}

interface TreeItem {
  id: UUID
  folderPath: String
  fileName: String
  title: String
}

type TreeItemFolder implements TreeItem {
  id: UUID
  childrenCount: Int
  depth: Int
  fileName: String
  folderPath: String
  title: String
  isAncestor: Boolean
}

type TreeItemPage implements TreeItem {
  id: UUID
  createdAt: Date
  depth: Int
  fileName: String
  folderPath: String
  editor: String
  pageType: String
  title: String
  updatedAt: Date
}

type TreeItemAsset implements TreeItem {
  id: UUID
  createdAt: Date
  depth: Int
  fileName: String
  # In Bytes
  fileSize: Int
  fileExt: String
  mimeType: String
  folderPath: String
  title: String
  updatedAt: Date
}
