{
  "openapi": "3.1.1",
  "info": {
    "title": "Board01 Company Agent API",
    "version": "1.0.0",
    "description": "Read a company's board, motions, deliberation records and company memory. Each bearer credential belongs to one company."
  },
  "servers": [
    {
      "url": "https://app.board01.com/api/v1"
    }
  ],
  "security": [
    {
      "companyBearer": []
    }
  ],
  "paths": {
    "/board": {
      "get": {
        "operationId": "getCompanyBoard",
        "summary": "Read the company board",
        "description": "Returns the company, current approval rule, seats and voting weights. The bearer credential identifies the company. This endpoint accepts no query parameters.",
        "responses": {
          "200": {
            "description": "Read the company board.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BoardResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/motions": {
      "get": {
        "operationId": "listCompanyMotions",
        "summary": "List company motions",
        "description": "Returns the newest motions first, ordered by creation time and then ID in descending order. Start without a cursor, then follow next_cursor until it is null. Each query parameter can appear once.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of motions on this page.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Motion ID returned in next_cursor by the preceding request.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List company motions.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MotionsPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/motions/{id}": {
      "get": {
        "operationId": "getCompanyMotion",
        "summary": "Read a company motion",
        "description": "Returns the motion text, frozen seats, deliberation, ballots and weighted tally. This endpoint accepts no query parameters.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Motion ID from the company's motion list.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Read a company motion.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MotionResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/memory": {
      "get": {
        "operationId": "getCompanyMemory",
        "summary": "Read company memory",
        "description": "Returns the company profile and up to three recent closed motions, newest first. Access requires company memory to be enabled. This endpoint accepts no query parameters.",
        "responses": {
          "200": {
            "description": "Read company memory.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MemoryResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidInput"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "companyBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Send the company agent credential in the Authorization header. Keep it in server-side secret storage."
      }
    },
    "responses": {
      "InvalidInput": {
        "description": "A path or query parameter is invalid.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/APIError",
              "properties": {
                "error": {
                  "const": "invalid_input"
                }
              }
            },
            "example": {
              "error": "invalid_input"
            }
          }
        }
      },
      "Unauthenticated": {
        "description": "The company credential is missing, invalid, expired or revoked.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/APIError",
              "properties": {
                "error": {
                  "const": "unauthenticated"
                }
              }
            },
            "example": {
              "error": "unauthenticated"
            }
          }
        },
        "headers": {
          "WWW-Authenticate": {
            "schema": {
              "type": "string"
            },
            "description": "A Bearer challenge for the Board01 realm."
          }
        }
      },
      "Forbidden": {
        "description": "The company does not have access to the requested resource.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/APIError",
              "properties": {
                "error": {
                  "const": "forbidden"
                }
              }
            },
            "example": {
              "error": "forbidden"
            }
          }
        }
      },
      "NotFound": {
        "description": "The resource or cursor is unknown to this company.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/APIError",
              "properties": {
                "error": {
                  "const": "not_found"
                }
              }
            },
            "example": {
              "error": "not_found"
            }
          }
        }
      },
      "Unavailable": {
        "description": "Board01 could not read the resource at this time.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/APIError",
              "properties": {
                "error": {
                  "const": "unavailable"
                }
              }
            },
            "example": {
              "error": "unavailable"
            }
          }
        }
      }
    },
    "schemas": {
      "ApprovalRule": {
        "type": "string",
        "enum": [
          "weighted_majority",
          "human_unanimity"
        ]
      },
      "MotionStatus": {
        "type": "string",
        "enum": [
          "discussion",
          "researching",
          "research_failed",
          "voting",
          "closed"
        ]
      },
      "Decision": {
        "type": "string",
        "enum": [
          "approved",
          "rejected"
        ]
      },
      "VoteChoice": {
        "type": "string",
        "enum": [
          "yes",
          "no",
          "abstain"
        ]
      },
      "Board": {
        "type": "object",
        "required": [
          "slug",
          "name",
          "approval_rule",
          "seats"
        ],
        "properties": {
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "approval_rule": {
            "$ref": "#/components/schemas/ApprovalRule"
          },
          "seats": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CurrentSeat"
            },
            "description": "Current voting seats. Their weights sum to 6000 units."
          }
        },
        "additionalProperties": false
      },
      "BoardResult": {
        "type": "object",
        "required": [
          "board"
        ],
        "properties": {
          "board": {
            "$ref": "#/components/schemas/Board"
          }
        },
        "additionalProperties": false
      },
      "MotionSummary": {
        "type": "object",
        "required": [
          "id",
          "title",
          "status",
          "outcome",
          "created_at",
          "closed_at",
          "language"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/MotionStatus"
          },
          "outcome": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "approved",
              "rejected",
              null
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "closed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "language": {
            "type": "string",
            "enum": [
              "es",
              "en",
              "pt",
              "fr"
            ]
          }
        },
        "additionalProperties": false
      },
      "MotionsPage": {
        "type": "object",
        "required": [
          "motions",
          "next_cursor"
        ],
        "properties": {
          "motions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MotionSummary"
            },
            "maxItems": 50
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Pass this value unchanged as cursor to fetch the next page. A null value marks the end of the list."
          }
        },
        "additionalProperties": false
      },
      "HumanSeat": {
        "type": "object",
        "required": [
          "key",
          "kind",
          "weight_units"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "Stable seat identifier."
          },
          "kind": {
            "type": "string",
            "const": "human"
          },
          "weight_units": {
            "type": "integer",
            "minimum": 0,
            "maximum": 6000
          }
        },
        "additionalProperties": false
      },
      "CurrentAISeat": {
        "type": "object",
        "required": [
          "key",
          "kind",
          "weight_units",
          "label"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "Stable seat identifier."
          },
          "kind": {
            "type": "string",
            "const": "ai"
          },
          "weight_units": {
            "type": "integer",
            "minimum": 0,
            "maximum": 6000
          },
          "label": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "CurrentSeat": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/HumanSeat"
          },
          {
            "$ref": "#/components/schemas/CurrentAISeat"
          }
        ],
        "description": "A current board seat. Divide weight_units by 6000 to obtain its share of the total."
      },
      "AISeat": {
        "type": "object",
        "required": [
          "key",
          "kind",
          "weight_units",
          "label",
          "model"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "Stable seat identifier."
          },
          "kind": {
            "type": "string",
            "const": "ai"
          },
          "weight_units": {
            "type": "integer",
            "minimum": 0,
            "maximum": 6000
          },
          "label": {
            "type": "string"
          },
          "model": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "Seat": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/HumanSeat"
          },
          {
            "$ref": "#/components/schemas/AISeat"
          }
        ],
        "description": "Seat and voting weight frozen for this motion. Divide weight_units by 6000 to obtain its share of the total."
      },
      "Objection": {
        "type": "object",
        "required": [
          "target",
          "point"
        ],
        "properties": {
          "target": {
            "type": "string",
            "description": "Stable seat identifier."
          },
          "point": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "VoteReply": {
        "type": "object",
        "required": [
          "from",
          "answer"
        ],
        "properties": {
          "from": {
            "type": "string",
            "description": "Stable seat identifier."
          },
          "answer": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "RecordedReply": {
        "type": "object",
        "required": [
          "from",
          "point",
          "answer"
        ],
        "properties": {
          "from": {
            "type": "string",
            "description": "Stable seat identifier."
          },
          "point": {
            "type": "string"
          },
          "answer": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "Ballot": {
        "type": "object",
        "required": [
          "seat_key",
          "choice",
          "reason",
          "created_at"
        ],
        "properties": {
          "seat_key": {
            "type": "string",
            "description": "Stable seat identifier."
          },
          "choice": {
            "$ref": "#/components/schemas/VoteChoice"
          },
          "reason": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "model": {
            "type": "string"
          },
          "effort": {
            "type": "string"
          },
          "position": {
            "type": "string"
          },
          "objections": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Objection"
            }
          },
          "responses": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RecordedReply"
            }
          }
        },
        "additionalProperties": false,
        "description": "A deposited vote. AI votes can also include the model, reasoning effort, position, objections and replies recorded for that ballot."
      },
      "PositionEvent": {
        "type": "object",
        "required": [
          "attempt",
          "seat",
          "model",
          "provider_model",
          "provider_id",
          "created_at",
          "stage",
          "content"
        ],
        "properties": {
          "attempt": {
            "type": "integer",
            "minimum": 1
          },
          "seat": {
            "type": "string",
            "description": "Stable seat identifier."
          },
          "model": {
            "type": "string"
          },
          "provider_model": {
            "type": [
              "string",
              "null"
            ]
          },
          "provider_id": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "stage": {
            "type": "string",
            "const": "position"
          },
          "content": {
            "type": "object",
            "required": [
              "position"
            ],
            "properties": {
              "position": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      },
      "ObjectionsEvent": {
        "type": "object",
        "required": [
          "attempt",
          "seat",
          "model",
          "provider_model",
          "provider_id",
          "created_at",
          "stage",
          "content"
        ],
        "properties": {
          "attempt": {
            "type": "integer",
            "minimum": 1
          },
          "seat": {
            "type": "string",
            "description": "Stable seat identifier."
          },
          "model": {
            "type": "string"
          },
          "provider_model": {
            "type": [
              "string",
              "null"
            ]
          },
          "provider_id": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "stage": {
            "type": "string",
            "const": "objections"
          },
          "content": {
            "type": "object",
            "required": [
              "objections"
            ],
            "properties": {
              "objections": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Objection"
                }
              }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      },
      "VoteEvent": {
        "type": "object",
        "required": [
          "attempt",
          "seat",
          "model",
          "provider_model",
          "provider_id",
          "created_at",
          "stage",
          "content"
        ],
        "properties": {
          "attempt": {
            "type": "integer",
            "minimum": 1
          },
          "seat": {
            "type": "string",
            "description": "Stable seat identifier."
          },
          "model": {
            "type": "string"
          },
          "provider_model": {
            "type": [
              "string",
              "null"
            ]
          },
          "provider_id": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "stage": {
            "type": "string",
            "const": "vote"
          },
          "content": {
            "type": "object",
            "required": [
              "choice",
              "reason",
              "responses"
            ],
            "properties": {
              "choice": {
                "$ref": "#/components/schemas/VoteChoice"
              },
              "reason": {
                "type": "string"
              },
              "responses": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/VoteReply"
                }
              }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      },
      "CouncilEvent": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/PositionEvent"
          },
          {
            "$ref": "#/components/schemas/ObjectionsEvent"
          },
          {
            "$ref": "#/components/schemas/VoteEvent"
          }
        ],
        "description": "An intervention recorded during a deliberation. The stage determines the shape of content."
      },
      "Tally": {
        "type": "object",
        "required": [
          "yes",
          "no",
          "abstain",
          "pending"
        ],
        "properties": {
          "yes": {
            "type": "integer",
            "minimum": 0,
            "maximum": 6000
          },
          "no": {
            "type": "integer",
            "minimum": 0,
            "maximum": 6000
          },
          "abstain": {
            "type": "integer",
            "minimum": 0,
            "maximum": 6000
          },
          "pending": {
            "type": "integer",
            "minimum": 0,
            "maximum": 6000
          }
        },
        "additionalProperties": false,
        "description": "Weighted totals in units. All four categories sum to 6000, including votes pending."
      },
      "Motion": {
        "type": "object",
        "required": [
          "id",
          "title",
          "status",
          "outcome",
          "created_at",
          "closed_at",
          "language",
          "motion",
          "approval_rule",
          "seats",
          "ballots",
          "events",
          "tally_units"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/MotionStatus"
          },
          "outcome": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "approved",
              "rejected",
              null
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "closed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "language": {
            "type": "string",
            "enum": [
              "es",
              "en",
              "pt",
              "fr"
            ]
          },
          "motion": {
            "type": "string",
            "description": "Text put to a vote."
          },
          "approval_rule": {
            "$ref": "#/components/schemas/ApprovalRule"
          },
          "seats": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Seat"
            }
          },
          "ballots": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Ballot"
            }
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CouncilEvent"
            },
            "maxItems": 9,
            "description": "Recorded interventions in the current or final deliberation attempt."
          },
          "tally_units": {
            "$ref": "#/components/schemas/Tally"
          }
        },
        "additionalProperties": false
      },
      "MotionResult": {
        "type": "object",
        "required": [
          "motion"
        ],
        "properties": {
          "motion": {
            "$ref": "#/components/schemas/Motion"
          }
        },
        "additionalProperties": false
      },
      "CompanyProfile": {
        "type": "object",
        "required": [
          "text",
          "revision",
          "updated_at"
        ],
        "properties": {
          "text": {
            "type": "string"
          },
          "revision": {
            "type": "integer",
            "minimum": 0
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "additionalProperties": false
      },
      "Minute": {
        "type": "object",
        "required": [
          "id",
          "title",
          "motion",
          "excerpt",
          "closed_at",
          "outcome"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "motion": {
            "type": "string",
            "maxLength": 900
          },
          "excerpt": {
            "type": "boolean",
            "description": "True when motion contains only the beginning of the original text."
          },
          "closed_at": {
            "type": "string",
            "format": "date-time"
          },
          "outcome": {
            "$ref": "#/components/schemas/Decision"
          }
        },
        "additionalProperties": false
      },
      "Memory": {
        "type": "object",
        "required": [
          "company",
          "profile",
          "minutes"
        ],
        "properties": {
          "company": {
            "type": "string"
          },
          "profile": {
            "$ref": "#/components/schemas/CompanyProfile"
          },
          "minutes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Minute"
            },
            "maxItems": 3
          }
        },
        "additionalProperties": false
      },
      "MemoryResult": {
        "type": "object",
        "required": [
          "memory"
        ],
        "properties": {
          "memory": {
            "$ref": "#/components/schemas/Memory"
          }
        },
        "additionalProperties": false
      },
      "APIError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "invalid_input",
              "unauthenticated",
              "forbidden",
              "not_found",
              "unavailable"
            ]
          }
        },
        "additionalProperties": false
      }
    }
  }
}
