# ===============================================
# PAGES
# ===============================================

extend type Query {
  pageHistoryById(
    id: Int!
    offsetPage: Int
    offsetSize: Int
  ): PageHistoryResult

  pageVersionById(
    pageId: Int!
    versionId: Int!
  ): PageVersion

  searchPages(
    """
    Site ID to search in (required)
    """
    siteId: UUID!
    """
    Search Query (required)
    """
    query: String!
    """
    The locale to perform the query as. Affects how the query is parsed by the search engine.
    """
    queryLocale: String
    """
    Only match pages that starts with the provided path.
    """
    path: String
    """
    Only match pages having one of the provided locales.
    """
    locale: [String]
    """
    Only match pages having one of the provided tags.
    """
    tags: [String]
    """
    Only match pages using the provided editor.
    """
    editor: String
    """
    Only match pages is the provided state.
    """
    publishState: PagePublishState
    """
    Result ordering. Defaults to relevancy.
    """
    orderBy: PageSearchSort
    """
    Result ordering direction. Defaults to descending.
    """
    orderByDirection: OrderByDirection
    """
    Result offset. Defaults to 0.
    """
    offset: Int
    """
    Results amount to return. Defaults to 25. Maximum 100.
    """
    limit: Int
  ): PageSearchResponse

  searchPagesAutocomplete(
    siteId: UUID!
    query: String!
  ): [String]

  pages(
    limit: Int
    orderBy: PageOrderBy
    orderByDirection: PageOrderByDirection
    tags: [String!]
    locale: String
    creatorId: Int
    authorId: Int
  ): [PageListItem]

  pageById(
    id: UUID!
    password: String
  ): Page

  pageByPath(
    siteId: UUID!
    path: String!
    password: String
  ): Page

  pageTree(
    path: String
    parent: Int
    mode: PageTreeMode!
    locale: String!
    includeAncestors: Boolean
  ): [PageTreeItem]

  pageLinks(
    locale: String!
  ): [PageLinkItem]

  pathFromAlias(
    siteId: UUID!
    alias: String!
  ): PageAliasPath

  tags(
    siteId: UUID!
  ): [PageTag]

  checkConflicts(
    id: Int!
    checkoutDate: Date!
  ): Boolean

  checkConflictsLatest(
    id: Int!
  ): PageConflictLatest
}

extend type Mutation {
  createPage(
    alias: String
    allowComments: Boolean
    allowContributions: Boolean
    allowRatings: Boolean
    content: String!
    description: String!
    editor: String!
    icon: String
    isBrowsable: Boolean
    isSearchable: Boolean
    locale: String!
    path: String!
    publishState: PagePublishState!
    publishEndDate: Date
    publishStartDate: Date
    relations: [PageRelationInput!]
    scriptCss: String
    scriptJsLoad: String
    scriptJsUnload: String
    showSidebar: Boolean
    showTags: Boolean
    showToc: Boolean
    siteId: UUID!
    tags: [String!]
    title: String!
    tocDepth: PageTocDepthInput
  ): PageResponse

  updatePage(
    id: UUID!
    patch: PageUpdateInput!
  ): PageResponse

  convertPage(
    id: UUID!
    editor: String!
  ): DefaultResponse

  renamePage(
    id: Int!
    destinationPath: String!
    destinationLocale: String!
  ): DefaultResponse

  deletePage(
    id: UUID!
  ): DefaultResponse

  deleteTag(
    id: Int!
  ): DefaultResponse

  updateTag(
    id: Int!
    tag: String!
    title: String!
  ): DefaultResponse

  flushCache: DefaultResponse

  migrateToLocale(
    sourceLocale: String!
    targetLocale: String!
  ): PageMigrationResponse

  rebuildPageTree: DefaultResponse

  rerenderPage(
    id: UUID!
  ): DefaultResponse

  restorePage(
    pageId: Int!
    versionId: Int!
  ): DefaultResponse

  purgePagesHistory (
    olderThan: String!
  ): DefaultResponse
}

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

type PageResponse {
  operation: Operation
  page: Page
}

type PageMigrationResponse {
  operation: Operation
  count: Int
}

type Page {
  alias: String
  allowComments: Boolean
  allowContributions: Boolean
  allowRatings: Boolean
  author: User
  content: String
  contentType: String
  createdAt: Date
  creator: User
  description: String
  editor: String
  hash: String
  icon: String
  id: UUID
  isBrowsable: Boolean
  isSearchable: Boolean
  locale: String
  navigationId: UUID
  navigationMode: NavigationMode
  password: String
  path: String
  publishEndDate: Date
  publishStartDate: Date
  publishState: PagePublishState
  relations: [PageRelation]
  render: String
  scriptJsLoad: String
  scriptJsUnload: String
  scriptCss: String
  showSidebar: Boolean
  showTags: Boolean
  showToc: Boolean
  siteId: UUID
  tags: [String]
  title: String
  toc: [JSON]
  tocDepth: PageTocDepth
  updatedAt: Date
}

type PageTag {
  id: UUID
  tag: String
  usageCount: Int
  siteId: UUID
  createdAt: Date
  updatedAt: Date
}

type PageHistory {
  versionId: Int
  versionDate: Date
  authorId: Int
  authorName: String
  actionType: String
  valueBefore: String
  valueAfter: String
}

type PageVersion {
  action: String
  authorId: String
  authorName: String
  content: String
  contentType: String
  createdAt: Date
  versionDate: Date
  description: String
  editor: String
  isPrivate: Boolean
  isPublished: Boolean
  locale: String
  pageId: Int
  path: String
  publishEndDate: Date
  publishStartDate: Date
  render: String
  tags: [String]
  title: String
  versionId: Int
}

type PageHistoryResult {
  trail: [PageHistory]
  total: Int
}

type PageSearchResponse {
  results: [PageSearchResult]
  totalHits: Int
}

type PageSearchResult {
  description: String
  highlight: String
  icon: String
  id: UUID
  locale: String
  path: String
  relevancy: Float
  tags: [String]
  title: String
  updatedAt: Date
}

type PageListItem {
  id: Int
  path: String
  locale: String
  title: String
  description: String
  contentType: String
  isPublished: Boolean
  isPrivate: Boolean
  privateNS: String
  createdAt: Date
  updatedAt: Date
  tags: [String]
}

type PageTreeItem {
  id: Int
  path: String
  depth: Int
  title: String
  isPrivate: Boolean
  isFolder: Boolean
  privateNS: String
  parent: Int
  pageId: Int
  locale: String
}

type PageLinkItem {
  id: Int
  path: String
  title: String
  links: [String]
}

type PageConflictLatest {
  id: Int
  authorId: String
  authorName: String
  content: String
  createdAt: Date
  description: String
  isPublished: Boolean
  locale: String
  path: String
  tags: [String]
  title: String
  updatedAt: Date
}

type PageRelation {
  id: UUID
  position: PageRelationPosition
  label: String
  caption: String
  icon: String
  target: String
}
input PageRelationInput {
  id: UUID!
  position: PageRelationPosition!
  label: String!
  caption: String
  icon: String
  target: String!
}

input PageUpdateInput {
  alias: String
  allowComments: Boolean
  allowContributions: Boolean
  allowRatings: Boolean
  content: String
  description: String
  icon: String
  isBrowsable: Boolean
  isSearchable: Boolean
  password: String
  publishEndDate: Date
  publishStartDate: Date
  publishState: PagePublishState
  reasonForChange: String
  relations: [PageRelationInput!]
  scriptJsLoad: String
  scriptJsUnload: String
  scriptCss: String
  showSidebar: Boolean
  showTags: Boolean
  showToc: Boolean
  tags: [String!]
  title: String
  tocDepth: PageTocDepthInput
}

type PageAliasPath {
  id: UUID
  path: String
}

type PageTocDepth {
  min: Int
  max: Int
}

input PageTocDepthInput {
  min: Int!
  max: Int!
}

enum PageSearchSort {
  relevancy
  title
  updatedAt
}

enum PageOrderBy {
  CREATED
  ID
  PATH
  TITLE
  UPDATED
}

enum PageOrderByDirection {
  ASC
  DESC
}

enum PageTreeMode {
  FOLDERS
  PAGES
  ALL
}

enum PagePublishState {
  draft
  published
  scheduled
}

enum PageRelationPosition {
  left
  center
  right
}
