input DSInput {
  dsID: String
  dsName: String!
  dsType: String!
  dsURL: String!
  accessType: String!
  authType: String!
  basicAuthUsername: String
  basicAuthPassword: String
  scrapeInterval: Int!
  queryTimeout: Int!
  httpMethod: String!
  projectID: String
}

type DSResponse {
  dsID: String
  dsName: String
  dsType: String
  dsURL: String
  accessType: String
  authType: String
  basicAuthUsername: String
  basicAuthPassword: String
  scrapeInterval: Int
  queryTimeout: Int
  httpMethod: String
  projectID: ID!
  healthStatus: String!
  createdAt: String
  updatedAt: String
}

input CreateDBInput {
  dsID: String!
  dbName: String!
  dbTypeName: String!
  dbTypeID: String!
  dbInformation: String
  chaosEventQueryTemplate: String!
  chaosVerdictQueryTemplate: String!
  applicationMetadataMap: [ApplicationMetadata]
  panelGroups: [PanelGroup]!
  endTime: String!
  startTime: String!
  projectID: ID!
  clusterID: ID!
  refreshRate: String!
}

input ApplicationMetadata {
  namespace: String!
  applications: [Resource]
}

input Resource {
  kind: String!
  names: [String]
}

input UpdateDBInput {
  dbID: String!
  dsID: String
  dbName: String
  dbTypeName: String
  dbTypeID: String
  dbInformation: String
  chaosEventQueryTemplate: String
  chaosVerdictQueryTemplate: String
  applicationMetadataMap: [ApplicationMetadata]
  panelGroups: [UpdatePanelGroupInput]
  endTime: String
  startTime: String
  clusterID: ID
  refreshRate: String
}

input UpdatePanelGroupInput {
  panelGroupName: String!
  panelGroupID: String!
  panels: [Panel]
}

input PanelGroup {
  panels: [Panel]
  panelGroupName: String!
}

input Panel {
  panelID: String
  dbID: String
  yAxisLeft: String
  yAxisRight: String
  xAxisDown: String
  unit: String
  panelGroupID: String
  createdAt: String
  promQueries: [PromQuery]
  panelOptions: PanelOption
  panelName: String!
}

input PanelOption {
  points: Boolean
  grIDs: Boolean
  leftAxis: Boolean
}

input PromQuery {
  queryID: String!
  promQueryName: String
  legend: String
  resolution: String
  minstep: String
  line: Boolean
  closeArea: Boolean
}

input PrometheusDataRequest {
  queries: [PromQueryInput]
  dsDetails: DsDetails!
}

input PromSeriesInput {
  series: String!
  dsDetails: DsDetails!
}

input DsDetails {
  url: String!
  start: String!
  end: String!
}

input PromQueryInput {
  queryID: String!
  query: String!
  legend: String
  resolution: String
  minstep: Int!
}

input QueryMapForPanel {
  panelID: String!
  queryIDs: [String!]!
}

input QueryMapForPanelGroup {
  panelGroupID: String!
  panelQueryMap: [QueryMapForPanel!]!
}

input DataVars {
  url: String!
  start: String!
  end: String!
  relativeTime: Int!
  refreshInterval: Int!
}

type MetricsPromResponse {
  queryID: String!
  legends: [String]
  tsvs: [[MetricsTimeStampValue]]
}

type MetricsTimeStampValue {
  date: Float
  value: Float
}

type SubData {
  date: Float
  value: String!
  subDataName: String!
}

type AnnotationsPromResponse {
  queryID: String!
  legends: [String]
  tsvs: [[AnnotationsTimeStampValue]]
  subDataArray: [[SubData]]
}

type AnnotationsTimeStampValue {
  date: Float
  value: Int
}

type PrometheusDataResponse {
  metricsResponse: [MetricsPromResponse]
  annotationsResponse: [AnnotationsPromResponse]
}

type MetricDataForPanel {
  panelID: String!
  panelMetricsResponse: [MetricsPromResponse]
}

type MetricDataForPanelGroup {
  panelGroupID: String!
  panelGroupMetricsResponse: [MetricDataForPanel]
}

type DashboardPromResponse {
  dashboardMetricsResponse: [MetricDataForPanelGroup]
  annotationsResponse: [AnnotationsPromResponse]
}

type PromSeriesResponse {
  series: String!
  labelValues: [LabelValue]
}

type PromSeriesListResponse {
  seriesList: [String]
}

type LabelValue {
  label: String!
  values: [Option]
}

type Option {
  name: String!
}

type ListDashboardResponse {
  dsID: String!
  dbID: String!
  dbName: String!
  dbTypeID: String!
  dbTypeName: String!
  dbInformation: String
  chaosEventQueryTemplate: String!
  chaosVerdictQueryTemplate: String!
  applicationMetadataMap: [ApplicationMetadataResponse]
  clusterName: String
  dsName: String
  dsType: String
  dsURL: String
  dsHealthStatus: String
  panelGroups: [PanelGroupResponse]!
  endTime: String!
  startTime: String!
  refreshRate: String!
  projectID: ID!
  clusterID: ID!
  createdAt: String
  updatedAt: String
  viewedAt: String
}

type ApplicationMetadataResponse {
  namespace: String!
  applications: [ResourceResponse]
}

type ResourceResponse {
  kind: String!
  names: [String]
}

type PanelGroupResponse {
  panels: [PanelResponse]
  panelGroupName: String!
  panelGroupID: String
}

type PanelResponse {
  panelID: String!
  yAxisLeft: String
  yAxisRight: String
  xAxisDown: String
  unit: String
  promQueries: [PromQueryResponse]
  panelOptions: PanelOptionResponse
  panelName: String
  createdAt: String
}

type PanelOptionResponse {
  points: Boolean
  grIDs: Boolean
  leftAxis: Boolean
}

type PromQueryResponse {
  queryID: ID!
  promQueryName: String
  legend: String
  resolution: String
  minstep: String
  line: Boolean
  closeArea: Boolean
}

input DeleteDSInput {
  forceDelete: Boolean!
  dsID: ID!
}

enum TimeFrequency {
  DAILY
  HOURLY
  MONTHLY
}

type WorkflowStatsResponse {
  date: Float!
  value: Int!
}

type WorkflowRunDetails {
  noOfRuns: Int!
  dateStamp: Float!
}

type WorkflowRunsData {
  value: Float
  workflowRunDetail: WorkflowRunDetails
}

type HeatmapDataResponse {
  bins: [WorkflowRunsData]!
}

input WorkflowRunStatsRequest {
  projectID: ID!
  workflowIDs: [ID]
}

type WorkflowRunStatsResponse {
  totalWorkflowRuns: Int!
  succeededWorkflowRuns: Int!
  failedWorkflowRuns: Int!
  runningWorkflowRuns: Int!
  averageResiliencyScore: Float!
  totalExperiments: Int!
  experimentsPassed: Int!
  experimentsFailed: Int!
  experimentsAwaited: Int!
  experimentsStopped: Int!
  experimentsNa: Int!
  passedPercentage: Float!
  failedPercentage: Float!
  workflowRunSucceededPercentage: Float!
  workflowRunFailedPercentage: Float!
}

type PortalDashboardDataResponse {
  name: String!
  dashboardData: String!
}


extend type Mutation {
  # ANALYTICS OPERATIONS
  """
  Creates a new datasource
  """
  createDataSource(datasource: DSInput): DSResponse @authorized

  """
  Creates a new analytics dashboard
  """
  createDashBoard(dashboard: CreateDBInput): ListDashboardResponse! @authorized

  """
  Updates a datasource
  """
  updateDataSource(datasource: DSInput!): DSResponse! @authorized

  """
  Updates a dashboard
  """
  updateDashboard(
    projectID: String!
    dashboard: UpdateDBInput!
    chaosQueryUpdate: Boolean!
  ): String! @authorized

  """
  Updates a dashboard panel
  """
  updatePanel(panelInput: [Panel]): String! @authorized

  """
  Deletes a dashboard
  """
  deleteDashboard(projectID: String!, dbID: String): Boolean! @authorized

  """
  Deletes a datasource
  """
  deleteDataSource(projectID: String!, input: DeleteDSInput!): Boolean!
  @authorized
}

extend type Query {
  # ANALYTICS OPERATIONS
  """
  Returns the workflow run data for a particular workflow in heatmap bins format
  """
  listHeatmapData(
    projectID: String!
    workflowID: String!
    year: Int!
  ): [HeatmapDataResponse]! @authorized

  """
  Returns the workflow and runs data divided in time frequency (hourly/daily/monthly)
  """
  listWorkflowStats(
    projectID: ID!
    filter: TimeFrequency!
    showWorkflowRuns: Boolean!
  ): [WorkflowStatsResponse]! @authorized

  """
  Returns metadata for multiple workflowIDs
  """
  getWorkflowRunStats(
    workflowRunStatsRequest: WorkflowRunStatsRequest!
  ): WorkflowRunStatsResponse! @authorized

  """
  Returns all the data sources for the projectID
  """
  listDataSource(projectID: String!): [DSResponse]! @authorized

  """
  Takes prometheus queries and returns response for annotations and metrics with a query map
  """
  getPrometheusData(request: PrometheusDataRequest): PrometheusDataResponse!
  @authorized

  """
  Return the prometheus labels and values for a given input
  """
  getPromLabelNamesAndValues(request: PromSeriesInput): PromSeriesResponse!
  @authorized

  """
  Return a list of all the prometheus series
  """
  getPromSeriesList(request: DsDetails): PromSeriesListResponse! @authorized

  """
  Returns a list of all the dashboards given an input
  """
  listDashboard(
    projectID: String!
    clusterID: String
    dbID: String
  ): [ListDashboardResponse] @authorized

  """
  Returns the portal dashboard data from the ChaosHub
  """
  listPortalDashboardData(
    projectID: String!
    hubName: String!
  ): [PortalDashboardDataResponse!]! @authorized
}

extend type Subscription {
  # ANALYTICS OPERATIONS
  """
  Takes a dashboard view id, prometheus queries, dashboard query map
  and data variables to query prometheus and send data periodically to the subscribed client
  """
  viewDashboard(
    dashboardID: String
    promQueries: [PromQueryInput!]!
    dashboardQueryMap: [QueryMapForPanelGroup!]!
    dataVariables: DataVars!
  ): DashboardPromResponse! @authorized
}
