# ===============================================
# SYSTEM
# ===============================================

extend type Query {
  systemExtensions: [SystemExtension]
  systemFlags: JSON
  systemInfo: SystemInfo
  systemInstances: [SystemInstance]
  systemSecurity: SystemSecurity
  systemJobs(
    states: [SystemJobState]
  ): [SystemJob]
  systemJobsScheduled: [SystemJobScheduled]
  systemJobsUpcoming: [SystemJobUpcoming]
  systemSearch: SystemSearch
}

extend type Mutation {
  cancelJob(
    id: UUID!
  ): DefaultResponse

  checkForUpdates: SystemCheckUpdateResponse

  disconnectWS: DefaultResponse

  installExtension(
    key: String!
  ): DefaultResponse

  rebuildSearchIndex: DefaultResponse

  retryJob(
    id: UUID!
  ): DefaultResponse

  updateSystemSearch(
    termHighlighting: Boolean
    dictOverrides: String
  ): DefaultResponse

  updateSystemFlags(
    flags: JSON!
  ): DefaultResponse

  updateSystemSecurity(
    authJwtAudience: String
    authJwtExpiration: String
    authJwtRenewablePeriod: String
    corsConfig: String
    corsMode: SystemSecurityCorsMode
    cspDirectives: String
    disallowFloc: Boolean
    disallowIframe: Boolean
    disallowOpenRedirect: Boolean
    enforceCsp: Boolean
    enforceHsts: Boolean
    enforceSameOriginReferrerPolicy: Boolean
    forceAssetDownload: Boolean
    hstsDuration: Int
    trustProxy: Boolean
    uploadMaxFiles: Int
    uploadMaxFileSize: Int
    uploadScanSVG: Boolean
  ): DefaultResponse
}

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

type SystemInfo {
  configFile: String
  cpuCores: Int
  currentVersion: String
  dbHost: String
  dbType: String
  dbVersion: String
  groupsTotal: Int
  hostname: String
  httpPort: Int
  httpRedirection: Boolean
  httpsPort: Int
  isMailConfigured: Boolean
  isSchedulerHealthy: Boolean
  latestVersion: String
  latestVersionReleaseDate: Date
  loginsPastDay: Int
  nodeVersion: String
  operatingSystem: String
  pagesTotal: Int
  platform: String
  ramTotal: String
  sslDomain: String
  sslExpirationDate: Date
  sslProvider: String
  sslStatus: String
  sslSubscriberEmail: String
  tagsTotal: Int
  upgradeCapable: Boolean
  usersTotal: Int
  workingDirectory: String
}

type SystemInstance {
  id: String
  activeConnections: Int
  activeListeners: Int
  dbUser: String
  dbFirstSeen: Date
  dbLastSeen: Date
  ip: String
}

enum SystemImportUsersGroupMode {
  MULTI
  SINGLE
  NONE
}

type SystemImportUsersResponse {
  operation: Operation
  usersCount: Int
  groupsCount: Int
  failed: [SystemImportUsersResponseFailed]
}

type SystemImportUsersResponseFailed {
  provider: String
  email: String
  error: String
}

type SystemExtension {
  key: String
  title: String
  description: String
  isInstalled: Boolean
  isInstallable: Boolean
  isCompatible: Boolean
}

type SystemSecurity {
  authJwtAudience: String
  authJwtExpiration: String
  authJwtRenewablePeriod: String
  corsConfig: String
  corsMode: SystemSecurityCorsMode
  cspDirectives: String
  disallowFloc: Boolean
  disallowIframe: Boolean
  disallowOpenRedirect: Boolean
  enforceCsp: Boolean
  enforceHsts: Boolean
  enforceSameOriginReferrerPolicy: Boolean
  forceAssetDownload: Boolean
  hstsDuration: Int
  trustProxy: Boolean
  uploadMaxFiles: Int
  uploadMaxFileSize: Int
  uploadScanSVG: Boolean
}

enum SystemSecurityCorsMode {
  OFF
  REFLECT
  HOSTNAMES
  REGEX
}

type SystemJob {
  id: UUID
  task: String
  state: SystemJobState
  useWorker: Boolean
  wasScheduled: Boolean
  payload: JSON
  attempt: Int
  maxRetries: Int
  lastErrorMessage: String
  executedBy: String
  createdAt: Date
  startedAt: Date
  completedAt: Date
}

type SystemJobScheduled {
  id: UUID
  task: String
  cron: String
  type: String
  payload: JSON
  createdAt: Date
  updatedAt: Date
}

type SystemJobUpcoming {
  id: UUID
  task: String
  useWorker: Boolean
  payload: JSON
  retries: Int
  maxRetries: Int
  waitUntil: Date
  isScheduled: Boolean
  createdBy: String
  createdAt: Date
  updatedAt: Date
}

enum SystemJobState {
  ACTIVE
  COMPLETED
  FAILED
  INTERRUPTED
}

type SystemCheckUpdateResponse {
  operation: Operation
  current: String
  latest: String
  latestDate: String
}

type SystemSearch {
  termHighlighting: Boolean
  dictOverrides: String
}