{
  "openapi": "3.1.0",
  "info": {
    "title": "Winloom API",
    "version": "v1",
    "description": "Push accounts into a Winloom workspace and read back sourced facts about them. The workspace is taken from the bearer token; no parameter names one.",
    "contact": { "email": "hello@winloom.ai" }
  },
  "servers": [ { "url": "https://api.winloom.ai" } ],
  "security": [ { "bearer": [] } ],
  "paths": {
    "/health": {
      "get": {
        "operationId": "health",
        "summary": "Liveness check",
        "security": [],
        "responses": {
          "200": { "description": "Up", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Health" } } } }
        }
      }
    },
    "/v1/accounts": {
      "get": {
        "operationId": "listAccounts",
        "summary": "The 100 most recent accounts, newest first",
        "description": "Requires scope `read`.",
        "responses": {
          "200": { "description": "Accounts", "content": { "application/json": { "schema": {
            "type": "object", "required": ["data"],
            "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/Account" } } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      },
      "post": {
        "operationId": "createAccount",
        "summary": "Create an account and queue research on it",
        "description": "Requires scope `write`. Returns immediately; research runs in the background.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": {
          "type": "object", "required": ["name", "domain"],
          "properties": {
            "name":   { "type": "string", "maxLength": 200 },
            "domain": { "type": "string", "maxLength": 253, "pattern": "^(?!-)[A-Za-z0-9-]{1,63}(\\.[A-Za-z0-9-]{1,63})+$", "description": "Bare hostname, lower-cased on save, unique per workspace." }
          } } } } },
        "responses": {
          "201": { "description": "Created", "content": { "application/json": { "schema": {
            "type": "object", "required": ["data"],
            "properties": { "data": { "type": "object", "required": ["id", "domain"],
              "properties": { "id": { "type": "integer" }, "domain": { "type": "string" } } } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "409": { "description": "domain_exists", "content": { "application/json": { "schema": {
            "type": "object", "properties": { "error": { "const": "domain_exists" }, "domain": { "type": "string" } } } } } },
          "422": { "$ref": "#/components/responses/ValidationFailed" }
        }
      }
    },
    "/v1/accounts/{id}": {
      "get": {
        "operationId": "getAccount",
        "summary": "One account with its sourced facts",
        "description": "Requires scope `read`. `claims` is empty until research has finished.",
        "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "integer" } } ],
        "responses": {
          "200": { "description": "Account", "content": { "application/json": { "schema": {
            "type": "object", "required": ["data"],
            "properties": { "data": { "type": "object", "required": ["account", "claims"],
              "properties": {
                "account": { "$ref": "#/components/schemas/Account" },
                "claims":  { "type": "array", "items": { "$ref": "#/components/schemas/Claim" } }
              } } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": { "bearer": { "type": "http", "scheme": "bearer" } },
    "schemas": {
      "Health": { "type": "object", "properties": {
        "status": { "const": "ok" }, "service": { "type": "string" }, "version": { "type": "string" }, "time": { "type": "string", "format": "date-time" } } },
      "Account": { "type": "object", "required": ["id", "name", "domain"], "properties": {
        "id": { "type": "integer" }, "name": { "type": "string" }, "domain": { "type": "string" }, "created_at": { "type": "string" } } },
      "Claim": { "type": "object", "required": ["predicate", "value", "source"], "properties": {
        "predicate": { "type": "string", "description": "e.g. company.industry. New predicates may appear within v1; ignore unknown ones." },
        "value": { "description": "Any JSON value." },
        "source": { "type": "object", "properties": { "url": { "type": "string", "format": "uri" }, "fetched_at": { "type": "string" } } } } },
      "Error": { "type": "object", "required": ["error"], "properties": {
        "error": { "type": "string" }, "required": { "type": "string" } } }
    },
    "responses": {
      "Unauthorized": { "description": "missing_bearer_token or invalid_token", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Forbidden": { "description": "insufficient_scope, tenant_disabled or token_has_no_tenant", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "NotFound": { "description": "not_found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "ValidationFailed": { "description": "Validation failed", "content": { "application/json": { "schema": {
        "type": "object", "properties": { "message": { "type": "string" }, "errors": { "type": "object", "additionalProperties": { "type": "array", "items": { "type": "string" } } } } } } } }
    }
  }
}
