type RepoProvider {
  id: ID!
  createdAt: DateTime!
  displayName: String!
  avatarUrl: String
  org: Org!
  type: RepoProviderType!
  key: String!
  link: String!
  repos: RepoProvidersRepos!
}

"""
A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date-time format.
"""
scalar DateTime

enum RepoProviderType {
  Custom
  GitHub
  Bitbucket
}

type User {
  id: ID!
  createdAt: DateTime!
  email: String!
  displayName: String!
  avatarUrl: String
  org: Org!
  orgs: [Org!]!
  invitations(skip: Int = 0, take: Int = 10, where: OrgInvitationFilter, order: OrgInvitationOrder): OrgInvitations!
}

input OrgInvitationFilter {
  id: StringFilter
  state: OrgInvitationStateFilter
  mine: Boolean
}

input StringFilter {
  eq: String
  lt: String
  lte: String
  gt: String
  gte: String
  null: Boolean
  not: StringFilter
  and: [StringFilter!]
  or: [StringFilter!]
}

input OrgInvitationStateFilter {
  eq: OrgInvitationState
  not: OrgInvitationStateFilter
  and: [OrgInvitationStateFilter!]
  or: [OrgInvitationStateFilter!]
}

enum OrgInvitationState {
  Pending
  Accepted
  Declined
}

input OrgInvitationOrder {
  createdAt: SortOrder
}

enum SortOrder {
  ASC
  DESC
}

type Org {
  id: ID!
  createdAt: DateTime!
  slug: String!
  name: String!
  agentConfigured: Boolean!
  avatarUrl: String
  repos(skip: Int = 0, take: Int = 10, where: RepoFilter, order: RepoOrder): [Repo!]!
  repoProviders: [RepoProvider!]!
  users(skip: Int = 0, take: Int = 10, where: UserFilter, order: UserOrder): Users!
  invitations(skip: Int = 0, take: Int = 10, where: OrgInvitationFilter, order: OrgInvitationOrder): OrgInvitations!
}

input RepoFilter {
  org: [String]
  id: StringFilter
  slug: StringFilter
  path: StringFilter
  provider: [ID]
  providerType: [RepoProviderType]
  providerSource: StringFilter
  dependsOn: StringFilter
}

input RepoOrder {
  createdAt: SortOrder
  lastActivity: SortOrder
}

input UserFilter {
  id: [ID]
  githubId: [String]
}

input UserOrder {
  createdAt: SortOrder
}

type AgentToken {
  id: ID!
  createdAt: DateTime!
  name: String!
  token: String!
  org: Org!
  default: Boolean!
}

type Agent {
  id: ID!
  createdAt: DateTime!
  org: Org!
  job: BuildJob
  name: String!
  platform: AgentPlatform!
  priority: Float!
  tags: [String!]!
  token: AgentToken!
  lastActivity: DateTime!
  jobs(skip: Int = 0, take: Int = 10, where: BuildJobFilter, order: BuildJobOrder): [BuildJob!]!
}

enum AgentPlatform {
  macOS
  Linux
  Windows
}

input BuildJobFilter {
  org: [String]
  repo: StringFilter
  build: IntFilter
  id: StringFilter
  number: IntFilter
  name: StringFilter
  slug: StringFilter
  path: StringFilter
  tags: [TagFilter!]
  state: [StepState]
}

input IntFilter {
  eq: Int
  lt: Int
  lte: Int
  gt: Int
  gte: Int
  null: Boolean
  not: IntFilter
  and: [IntFilter!]
  or: [IntFilter!]
}

input TagFilter {
  in: [String!]
  not: TagFilter
  and: [TagFilter!]
  or: [TagFilter!]
}

enum StepState {
  Waiting
  Pending
  Running
  Done
  Error
  DependencyFailed
}

input BuildJobOrder {
  createdAt: SortOrder
}

type BuildStepEnv {
  name: String!
  value: String!
  secret: Boolean!
}

type BuildStep {
  id: ID!
  createdAt: DateTime!
  org: Org!
  repo: Repo!
  build: Build!
  job: BuildJob!
  artifacts: [Artifact!]!
  dependencies: [BuildStep!]!
  dependents: [BuildStep!]!
  startedAt: DateTime
  completedAt: DateTime
  state: StepState!
  step: Int!
  path: String!
  name: String!
  command: [String!]!
  env: [BuildStepEnv!]!
  configId: String!
  output: String
}

type Artifact {
  id: ID!
  createdAt: DateTime!
  org: Org!
  repo: Repo!
  build: Build!
  job: BuildJob!
  step: BuildStep!
  key: String!
  path: String!
  size: Int!
  download: String!
}

type DockerOptions {
  image: String
  file: String
  context: String
}

type BuildJob {
  id: ID!
  createdAt: DateTime!
  name: String!
  slug: String!
  number: Float!
  path: String!
  startedAt: DateTime
  completedAt: DateTime
  state: StepState!
  docker: DockerOptions
  org: Org!
  agent: Agent!
  repo: Repo!
  build: Build!
  steps: [BuildStep!]!
  artifacts: [Artifact!]!
  tags: [String!]!
}

type BuildUser {
  id: ID!
  createdAt: DateTime!
  displayName: String!
  avatarUrl: String
  link: String
  provider: BuildUserProvider!
  providerId: String!
}

enum BuildUserProvider {
  Refloat
  GitHub
  Bitbucket
}

type BuildErrors {
  cancelled: Boolean!
  configNotFound: Boolean!
  config: String
}

type Build {
  id: ID!
  createdAt: DateTime!
  org: Org!
  repo: Repo!
  user: BuildUser!
  steps: [BuildStep!]!
  jobs: [BuildJob!]!
  artifacts: [Artifact!]!
  dependencyOf: Build
  dependencies: [Build!]!
  startedAt: DateTime
  completedAt: DateTime
  state: RunState!
  number: Float!
  path: String!
  sha: String!
  branch: String!
  message: String!
  errors: BuildErrors!
  config: BuildConfig
}

enum RunState {
  ConfigQueued
  ConfigParsing
  Pending
  Running
  Done
  Error
}

type PlatformConfigs {
  macos: String!
  linux: String!
  windows: String!
}

type BuildConfig {
  id: ID!
  createdAt: DateTime!
  build: Build!
  repos: [Repo!]!
  dependencies: [String!]!
  source: String!
  file: String!
  platforms: PlatformConfigs!
}

type Repo {
  id: ID!
  createdAt: DateTime!
  org: Org!
  public: Boolean!
  config: BuildConfig
  slug: String!
  path: String!
  defaultBranch: String!
  providerType: RepoProviderType!
  providerSource: String!
  configured: Boolean!
  lastActivity: DateTime!
  builds(skip: Int = 0, take: Int = 10, where: BuildFilter, order: BuildOrder): [Build!]!
}

input BuildFilter {
  id: [ID]
  number: [Int]
  org: [String]
  repo: [String]
  path: [String]
  dependencyOf: [ID]
}

input BuildOrder {
  createdAt: SortOrder
}

type ProviderRepo {
  id: ID!
  createdAt: DateTime!
  sourceId: String!
  name: String!
  source: String!
  configured: Boolean!
  defaultBranch: String!
  org: Org!
  provider: RepoProvider!
}

type OrgInvitation {
  id: ID!
  createdAt: DateTime!
  state: OrgInvitationState!
  email: String!
  org: Org!
}

type Cursor {
  current: String
  next: String
}

type OrgInvitations {
  cursor: Cursor!
  count: Int!
  one: OrgInvitation
  list: [OrgInvitation!]!
}

type Users {
  cursor: Cursor!
  count: Int!
  one: User
  list: [User!]!
}

type Repos {
  cursor: Cursor!
  count: Int!
  one: Repo
  list: [Repo!]!
}

type Orgs {
  cursor: Cursor!
  count: Int!
  one: Org
  list: [Org!]!
}

type AgentTokens {
  cursor: Cursor!
  count: Int!
  one: AgentToken
  list: [AgentToken!]!
}

type Agents {
  cursor: Cursor!
  count: Int!
  one: Agent
  list: [Agent!]!
}

type BuildJobs {
  cursor: Cursor!
  count: Int!
  one: BuildJob
  list: [BuildJob!]!
}

type Builds {
  cursor: Cursor!
  count: Int!
  one: Build
  list: [Build!]!
}

type BuildSteps {
  cursor: Cursor!
  count: Int!
  one: BuildStep
  list: [BuildStep!]!
}

type RepoProvidersRepos {
  availableCount: Int!
  configuredCount: Int!
  availableRepos(skip: Int = 0, take: Int = 10, where: ProviderRepoFilter, order: ProviderRepoOrder): [ProviderRepo!]!
  configuredRepos(skip: Int = 0, take: Int = 10, where: RepoFilter, order: RepoOrder): [Repo!]!
}

input ProviderRepoFilter {
  org: [String]
  id: [ID]
  name: [String]
  configured: Boolean
  provider: [ID]
}

input ProviderRepoOrder {
  createdAt: SortOrder
}

type ProviderRepos {
  cursor: Cursor!
  count: Int!
  one: ProviderRepo
  list: [ProviderRepo!]!
}

type BuildAgentMutation {
  acquire: Build
  error(notFound: Boolean, sha: String, error: String!, build: ID!): Build
  configure(config: RunConfigs, dependencies: [String!]!, sha: String!, build: ID!): Build
}

input RunConfigs {
  macos: String!
  linux: String!
  windows: String!
  source: String!
}

type JobAgentMutation {
  acquire: BuildJob
}

type StepAgentMutation {
  start(date: DateTime!, id: String!): BuildStep!
  complete(success: Boolean!, date: DateTime!, id: String!): BuildStep!
}

type AgentMutation {
  build: BuildAgentMutation!
  job: JobAgentMutation!
  step: StepAgentMutation!
  register(priority: Int, tags: [String!], platform: AgentPlatform!, token: String!, name: String!): AgentRegistration!
}

type AgentRegistration {
  token: String!
  agent: Agent!
}

type RepoMutation {
  import: RepoImportMutation!
}

type RepoImportMutation {
  provider(provider: RepoProviderType!, source: String!): Repo!
  custom(defaultBranch: String!, source: String!, name: String!, org: String!): Repo!
}

type OrgMutation {
  users: OrgUsersMutation!
  create(slug: String!, name: String!): Org!
}

type OrgUsersMutation {
  invite(email: String!, org: String!): OrgInvitation!
  remove(userId: String!, org: String!): Org!
}

type AuthMutation {
  signUp(remember: Boolean = true, password: String!, email: String!): User!
  signIn(remember: Boolean = true, password: String!, email: String!): User!
}

type CurrentUserMutation {
  invitation: UserInvitationMutation!
  org: UserOrgMutation!
  update(displayName: String): User!
}

type UserInvitationMutation {
  accept(id: String!): UserInvitationUpdate!
  decline(id: String!): UserInvitationUpdate!
}

type UserOrgMutation {
  create(slug: String!, name: String!): User!
}

type UserInvitationUpdate {
  user: User!
  invitation: OrgInvitation!
}

type Query {
  me: User
  org(skip: Int = 0, take: Int = 10, where: OrgFilter, order: OrgOrder): Orgs!
  agent(skip: Int = 0, take: Int = 10, where: AgentFilter, order: AgentOrder): Agents!
  agentToken(skip: Int = 0, take: Int = 10, where: AgentTokenFilter, order: AgentTokenOrder): AgentTokens!
  repo(skip: Int = 0, take: Int = 10, where: RepoFilter, order: RepoOrder): Repos!
  providerRepo(skip: Int = 0, take: Int = 10, where: ProviderRepoFilter, order: ProviderRepoOrder): ProviderRepos!
  build(skip: Int = 0, take: Int = 10, where: BuildFilter, order: BuildOrder): Builds!
  job(skip: Int = 0, take: Int = 10, where: BuildJobFilter, order: BuildJobOrder): BuildJobs!
  step(skip: Int = 0, take: Int = 10, where: BuildStepFilter, order: BuildStepOrder): BuildSteps!
}

input OrgFilter {
  id: [ID]
  slug: [String]
}

input OrgOrder {
  createdAt: SortOrder
}

input AgentFilter {
  org: [String]
  id: StringFilter
  name: StringFilter
  agentId: StringFilter
  tags: TagFilter
  hasJob: Boolean
  lastActivity: DateFilter
}

input DateFilter {
  eq: DateTime
  lt: DateTime
  lte: DateTime
  gt: DateTime
  gte: DateTime
  null: Boolean
  not: DateFilter
  and: [DateFilter!]
  or: [DateFilter!]
}

input AgentOrder {
  createdAt: SortOrder
  priority: SortOrder
  lastActivity: SortOrder
}

input AgentTokenFilter {
  org: [String]
  id: [ID]
  name: [String]
  token: [String]
}

input AgentTokenOrder {
  createdAt: SortOrder
}

input BuildStepFilter {
  org: [String]
  repo: [String]
  build: [Int]
  job: [String]
  id: [ID]
  number: [Int]
  name: [String]
  path: [String]
}

input BuildStepOrder {
  createdAt: SortOrder
}

type Mutation {
  runBuild(repo: String, org: String, message: String!, branch: String!, sha: String!): Build!
  agent: AgentMutation!
  repo: RepoMutation!
  org: OrgMutation!
  auth: AuthMutation!
  me: CurrentUserMutation!
}
