# Team domain types: Team, TeamAgent, TeamUser and related inputs.

type Team {
  id: ID!
  tenantId: ID!
  name: String!
  slug: String
  description: String
  type: String!
  status: String!
  budgetMonthlyCents: Int
  metadata: AWSJSON
  agents: [TeamAgent!]!
  users: [TeamUser!]!
  createdAt: AWSDateTime!
  updatedAt: AWSDateTime!
}

type TeamAgent {
  id: ID!
  teamId: ID!
  agentId: ID!
  tenantId: ID!
  agent: Agent
  role: String!
  joinedAt: AWSDateTime
  createdAt: AWSDateTime!
}

type TeamUser {
  id: ID!
  teamId: ID!
  userId: ID!
  tenantId: ID!
  user: User
  role: String!
  joinedAt: AWSDateTime
  createdAt: AWSDateTime!
}

# --- Inputs ---

input CreateTeamInput {
  tenantId: ID!
  name: String!
  description: String
  type: String
  budgetMonthlyCents: Int
  metadata: AWSJSON
  """
  Optional client-supplied idempotency key. See
  CreateAgentInput.idempotencyKey / packages/api/src/lib/idempotency.ts.
  """
  idempotencyKey: String
}

input UpdateTeamInput {
  name: String
  description: String
  type: String
  status: String
  budgetMonthlyCents: Int
  metadata: AWSJSON
}

input AddTeamAgentInput {
  agentId: ID!
  role: String
  "Optional idempotency key. See CreateTeamInput.idempotencyKey."
  idempotencyKey: String
}

input AddTeamUserInput {
  userId: ID!
  role: String
  "Optional idempotency key. See CreateTeamInput.idempotencyKey."
  idempotencyKey: String
}

# --- Query / Mutation extensions ---

extend type Query {
  teams(tenantId: ID!): [Team!]!
  team(id: ID!): Team
}

extend type Mutation {
  createTeam(input: CreateTeamInput!): Team!
  updateTeam(id: ID!, input: UpdateTeamInput!): Team!
  deleteTeam(id: ID!): Boolean!

  addTeamAgent(teamId: ID!, input: AddTeamAgentInput!): TeamAgent!
  removeTeamAgent(teamId: ID!, agentId: ID!): Boolean!

  addTeamUser(teamId: ID!, input: AddTeamUserInput!): TeamUser!
  removeTeamUser(teamId: ID!, userId: ID!): Boolean!
}
