# Auto-generated AppSync subscription-only schema.
# DO NOT EDIT — regenerate with: pnpm schema:build
#
# Source: packages/database-pg/graphql/types/subscriptions.graphql

scalar AWSDateTime
scalar AWSJSON

schema {
  query: Query
  mutation: Mutation
  subscription: Subscription
}

type Query {
  _empty: String
}

# AppSync Subscriptions — real-time event streams
#
# Each subscription filters by tenantId (or threadId) and is triggered
# by its corresponding notification mutation via @aws_subscribe.

# ────────────────────────────────────────────────────────────────────
# Event payload types
# ────────────────────────────────────────────────────────────────────

type AgentStatusEvent {
  agentId: ID!
  tenantId: ID!
  status: String!
  name: String!
  updatedAt: AWSDateTime!
}

type NewMessageEvent {
  messageId: ID!
  threadId: ID!
  tenantId: ID!
  role: String!
  content: String
  senderType: String
  senderId: ID
  ownerType: String
  ownerId: ID
  createdAt: AWSDateTime!
}

type HeartbeatActivityEvent {
  heartbeatId: ID!
  tenantId: ID!
  status: String!
  message: String
  createdAt: AWSDateTime!
}

type ThreadUpdateEvent {
  threadId: ID!
  tenantId: ID!
  status: String!
  title: String!
  updatedAt: AWSDateTime!
}

type InboxItemStatusEvent {
  inboxItemId: ID!
  tenantId: ID!
  status: String!
  title: String
  updatedAt: AWSDateTime!
}

type ThreadTurnUpdateEvent {
  runId: ID!
  triggerId: ID
  tenantId: ID!
  threadId: ID
  agentId: ID
  status: String!
  triggerName: String
  updatedAt: AWSDateTime!
}

type ComputerThreadChunkEvent {
  threadId: ID!
  chunk: AWSJSON
  seq: Int
  publishedAt: AWSDateTime!
}

type OrgUpdateEvent {
  tenantId: ID!
  changeType: String!
  entityType: String
  entityId: ID
  updatedAt: AWSDateTime!
}

type CostRecordedEvent {
  tenantId: ID!
  agentId: ID
  agentName: String
  eventType: String!
  amountUsd: Float!
  model: String
  updatedAt: AWSDateTime!
}

type EvalRunUpdateEvent {
  runId: ID!
  tenantId: ID!
  agentId: ID
  status: String!
  totalTests: Int
  passed: Int
  failed: Int
  passRate: Float
  errorMessage: String
  updatedAt: AWSDateTime!
}

# ────────────────────────────────────────────────────────────────────
# Notification mutations
#
# These are called by Lambda resolvers (not clients) to trigger the
# corresponding subscriptions. @aws_subscribe binds each subscription
# to the mutation(s) whose return type matches the event payload.
# ────────────────────────────────────────────────────────────────────

type Mutation {
  _empty: String
  notifyAgentStatus(
    agentId: ID!
    tenantId: ID!
    status: String!
    name: String!
  ): AgentStatusEvent @aws_api_key @aws_cognito_user_pools @aws_iam

  notifyNewMessage(
    messageId: ID!
    threadId: ID!
    tenantId: ID!
    role: String!
    content: String
    senderType: String
    senderId: ID
    ownerType: String
    ownerId: ID
  ): NewMessageEvent @aws_api_key @aws_cognito_user_pools @aws_iam

  notifyHeartbeatActivity(
    heartbeatId: ID!
    tenantId: ID!
    status: String!
    message: String
  ): HeartbeatActivityEvent @aws_api_key @aws_cognito_user_pools @aws_iam

  notifyThreadUpdate(
    threadId: ID!
    tenantId: ID!
    status: String!
    title: String!
  ): ThreadUpdateEvent @aws_api_key @aws_cognito_user_pools @aws_iam

  notifyInboxItemUpdate(
    inboxItemId: ID!
    tenantId: ID!
    status: String!
    title: String
  ): InboxItemStatusEvent @aws_api_key @aws_cognito_user_pools @aws_iam

  notifyThreadTurnUpdate(
    runId: ID!
    triggerId: ID
    tenantId: ID!
    threadId: ID
    agentId: ID
    status: String!
    triggerName: String
  ): ThreadTurnUpdateEvent @aws_api_key @aws_cognito_user_pools @aws_iam

  publishComputerThreadChunk(
    threadId: ID!
    chunk: AWSJSON!
    seq: Int!
  ): ComputerThreadChunkEvent! @aws_api_key @aws_cognito_user_pools @aws_iam

  notifyOrgUpdate(
    tenantId: ID!
    changeType: String!
    entityType: String
    entityId: ID
  ): OrgUpdateEvent @aws_api_key @aws_cognito_user_pools @aws_iam

  notifyCostRecorded(
    tenantId: ID!
    agentId: ID
    agentName: String
    eventType: String!
    amountUsd: Float!
    model: String
  ): CostRecordedEvent @aws_api_key @aws_cognito_user_pools @aws_iam

  notifyEvalRunUpdate(
    runId: ID!
    tenantId: ID!
    agentId: ID
    status: String!
    totalTests: Int
    passed: Int
    failed: Int
    passRate: Float
    errorMessage: String
  ): EvalRunUpdateEvent @aws_api_key @aws_cognito_user_pools @aws_iam
}

type Subscription {
  _empty: String
  onAgentStatusChanged(tenantId: ID!): AgentStatusEvent @aws_api_key @aws_cognito_user_pools @aws_iam
    @aws_subscribe(mutations: ["notifyAgentStatus"])

  onNewMessage(threadId: ID!): NewMessageEvent @aws_api_key @aws_cognito_user_pools @aws_iam
    @aws_subscribe(mutations: ["notifyNewMessage"])

  onHeartbeatActivity(tenantId: ID!): HeartbeatActivityEvent @aws_api_key @aws_cognito_user_pools @aws_iam
    @aws_subscribe(mutations: ["notifyHeartbeatActivity"])

  onThreadUpdated(tenantId: ID!): ThreadUpdateEvent @aws_api_key @aws_cognito_user_pools @aws_iam
    @aws_subscribe(mutations: ["notifyThreadUpdate"])

  onInboxItemStatusChanged(tenantId: ID!): InboxItemStatusEvent @aws_api_key @aws_cognito_user_pools @aws_iam
    @aws_subscribe(mutations: ["notifyInboxItemUpdate"])

  onThreadTurnUpdated(tenantId: ID!): ThreadTurnUpdateEvent @aws_api_key @aws_cognito_user_pools @aws_iam
    @aws_subscribe(mutations: ["notifyThreadTurnUpdate"])

  onComputerThreadChunk(threadId: ID!): ComputerThreadChunkEvent @aws_api_key @aws_cognito_user_pools @aws_iam
    @aws_subscribe(mutations: ["publishComputerThreadChunk"])

  onOrgUpdated(tenantId: ID!): OrgUpdateEvent @aws_api_key @aws_cognito_user_pools @aws_iam
    @aws_subscribe(mutations: ["notifyOrgUpdate"])

  onCostRecorded(tenantId: ID!): CostRecordedEvent @aws_api_key @aws_cognito_user_pools @aws_iam
    @aws_subscribe(mutations: ["notifyCostRecorded"])

  onEvalRunUpdated(tenantId: ID!): EvalRunUpdateEvent @aws_api_key @aws_cognito_user_pools @aws_iam
    @aws_subscribe(mutations: ["notifyEvalRunUpdate"])
}
