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

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

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

  searchPages(
    query: String!
    path: String
    locale: String
  ): PageSearchResponse!

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

  pageById(
    id: Int!
  ): Page

  tags: [PageTag]!

  searchTags(
    query: String!
  ): [String]!

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

  pageLinks(
    locale: String!
  ): [PageLinkItem]

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

  checkConflictsLatest(
    id: Int!
  ): PageConflictLatest!
}

extend type Mutation {
  createPage(
    siteId: UUID!
    content: String!
    description: String!
    editor: String!
    isPublished: Boolean!
    locale: String!
    path: String!
    publishEndDate: Date
    publishStartDate: Date
    scriptCss: String
    scriptJs: String
    tags: [String]!
    title: String!
  ): PageResponse

  updatePage(
    id: Int!
    content: String
    description: String
    editor: String
    isPublished: Boolean
    locale: String
    path: String
    publishEndDate: Date
    publishStartDate: Date
    scriptCss: String
    scriptJs: String
    tags: [String]
    title: String
  ): PageResponse

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

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

  deletePage(
    id: Int!
  ): DefaultResponse

  deleteTag(
    id: Int!
  ): DefaultResponse

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

  flushCache: DefaultResponse

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

  rebuildPageTree: DefaultResponse

  renderPage(
    id: Int!
  ): 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 {
  id: Int
  path: String
  hash: String
  title: String
  description: String
  isPublished: Boolean
  publishStartDate: Date
  publishEndDate: Date
  tags: [PageTag]
  content: String
  render: String
  toc: String
  contentType: String
  createdAt: Date
  updatedAt: Date
  editor: String
  locale: String
  scriptCss: String
  scriptJs: String
  authorId: Int
  authorName: String
  authorEmail: String
  creatorId: Int
  creatorName: String
  creatorEmail: String
}

type PageTag {
  id: Int
  tag: String
  title: String
  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
  tags: [String]
  title: String
  versionId: Int
}

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

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

type PageSearchResult {
  id: String
  title: String
  description: String
  path: String
  locale: String
}

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
}

enum PageOrderBy {
  CREATED
  ID
  PATH
  TITLE
  UPDATED
}

enum PageOrderByDirection {
  ASC
  DESC
}

enum PageTreeMode {
  FOLDERS
  PAGES
  ALL
}
