type Permission {
    resource: Resource!
    actions: [String!]!
}

type ApiKey {
    id: ID!
    name: String!
    description: String
    roles: [Role!]!
    createdAt: DateTime!
    permissions: [Permission!]!
}

type ApiKeyWithSecret {
    id: ID!
    key: String!
    name: String!
    description: String
    roles: [Role!]!
    createdAt: DateTime!
    permissions: [Permission!]!
}

input CreateApiKeyInput {
    name: String!
    description: String
    roles: [Role!]
    permissions: [AddPermissionInput!]
    """ This will replace the existing key if one already exists with the same name, otherwise returns the existing key """
    overwrite: Boolean
}

input AddPermissionInput {
    resource: Resource!
    actions: [String!]!
}

input AddRoleForUserInput {
    userId: ID!
    role: Role!
}

input AddRoleForApiKeyInput {
    apiKeyId: ID!
    role: Role!
}

input RemoveRoleFromApiKeyInput {
    apiKeyId: ID!
    role: Role!
}

type Mutation {
    createApiKey(input: CreateApiKeyInput!): ApiKeyWithSecret!
    addPermission(input: AddPermissionInput!): Boolean!
    addRoleForUser(input: AddRoleForUserInput!): Boolean!
    addRoleForApiKey(input: AddRoleForApiKeyInput!): Boolean!
    removeRoleFromApiKey(input: RemoveRoleFromApiKeyInput!): Boolean!
}

type Query {
    apiKeys: [ApiKey!]!
    apiKey(id: ID!): ApiKey
}
