{
  "openapi": "3.1.0",
  "info": {
    "title": "SilkTrain Employer Hiring API",
    "version": "1.0.0",
    "description": "Organization-scoped employer tools. Buyers review and publish drafts in their private workroom."
  },
  "servers": [
    {
      "url": "/api/v1"
    }
  ],
  "security": [
    {
      "employerKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "employerKey": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "BriefSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "title": {
            "type": "string"
          },
          "service": {
            "type": "string"
          },
          "mode": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "workflow": {
            "type": [
              "string",
              "null"
            ]
          },
          "platform": {
            "type": [
              "string",
              "null"
            ]
          },
          "proposals_count": {
            "type": "integer"
          }
        }
      },
      "Draft": {
        "type": "object",
        "properties": {
          "idempotency_key": {
            "type": "string",
            "format": "uuid"
          },
          "service": {
            "type": "string"
          },
          "mode": {
            "type": "string",
            "enum": [
              "hourly",
              "fixed",
              "managed"
            ]
          },
          "workflow": {
            "type": "string"
          },
          "platform": {
            "type": "string",
            "description": "Optional slug listed in /workflows."
          },
          "title": {
            "type": "string",
            "maxLength": 160
          },
          "outcome": {
            "type": "string",
            "minLength": 8,
            "maxLength": 5000
          },
          "acceptance": {
            "type": "string",
            "minLength": 8,
            "maxLength": 5000
          },
          "tools": {
            "type": "string",
            "maxLength": 1000
          }
        },
        "required": [
          "idempotency_key",
          "service",
          "mode",
          "title",
          "outcome",
          "acceptance"
        ]
      }
    }
  },
  "paths": {
    "/workflows": {
      "get": {
        "operationId": "listWorkflows",
        "summary": "List service codes, localized templates and nominated workspaces.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "services": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "specialties": {
                      "type": "object"
                    },
                    "workflows": {
                      "type": "object"
                    },
                    "templates": {
                      "type": "object"
                    },
                    "platforms": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "slug": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "modes": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit reached"
          }
        },
        "security": []
      }
    },
    "/capabilities": {
      "get": {
        "operationId": "getCapabilities",
        "summary": "Inspect this key’s current hiring permissions.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "version": {
                      "type": "integer"
                    },
                    "permissions": {
                      "type": "object",
                      "properties": {
                        "read_briefs": {
                          "type": "boolean"
                        },
                        "prepare_drafts": {
                          "type": "boolean"
                        }
                      }
                    },
                    "human_actions": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "spec": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit reached"
          },
          "401": {
            "description": "Invalid, expired or ineligible organization key."
          }
        }
      }
    },
    "/briefs": {
      "get": {
        "operationId": "listBriefs",
        "summary": "List briefs owned by the organization.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BriefSummary"
                      }
                    },
                    "next_after": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit reached"
          },
          "401": {
            "description": "Invalid, expired or ineligible organization key."
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "after",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ]
      }
    },
    "/briefs/{id}": {
      "get": {
        "operationId": "getBrief",
        "summary": "Read an owned brief and proposals.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "brief": {
                      "type": "object"
                    },
                    "proposals": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "workroom_url": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit reached"
          },
          "401": {
            "description": "Invalid, expired or ineligible organization key."
          },
          "404": {
            "description": "Brief unavailable to this organization."
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ]
      }
    },
    "/briefs/{id}/shortlist": {
      "get": {
        "operationId": "getShortlist",
        "summary": "List up to five eligible suggestions for an owned brief.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "workroom_url": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit reached"
          },
          "401": {
            "description": "Invalid, expired or ineligible organization key."
          },
          "404": {
            "description": "Brief unavailable to this organization."
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ]
      }
    },
    "/drafts": {
      "post": {
        "operationId": "prepareDraft",
        "summary": "Prepare an idempotent draft for human review.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "state": {
                      "type": "string"
                    },
                    "review_url": {
                      "type": "string"
                    },
                    "brief_id": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit reached"
          },
          "401": {
            "description": "Invalid, expired or ineligible organization key."
          },
          "200": {
            "description": "Identical draft already exists",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "state": {
                      "type": "string"
                    },
                    "review_url": {
                      "type": "string"
                    },
                    "brief_id": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Draft permission required"
          },
          "409": {
            "description": "Idempotency conflict"
          },
          "422": {
            "description": "Validation errors"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Draft"
              }
            }
          }
        }
      }
    }
  }
}
