{
  "openapi": "3.0.3",
  "info": {
    "title": "PerformaPeople Workspace API",
    "version": "0.1.0",
    "description": "A starter reference for selected existing workspace endpoints. These routes support the PerformaPeople application and are not yet a versioned public integration API. Coverage is intentionally partial. Authentication uses the signed-in browser session; API keys and service-to-service authentication are not currently provided."
  },
  "servers": [
    {
      "url": "/",
      "description": "Current PerformaPeople deployment"
    }
  ],
  "tags": [
    {
      "name": "Workspace",
      "description": "Session-scoped workspace reads."
    },
    {
      "name": "Authentication",
      "description": "Application sign-in flow."
    }
  ],
  "paths": {
    "/api/workspace/context": {
      "get": {
        "operationId": "getWorkspaceContext",
        "tags": [
          "Workspace"
        ],
        "summary": "Get the current workspace context",
        "description": "Returns the signed-in viewer and organization. Platform administrators in preview or impersonation mode may receive additional context. The session determines the organization; callers cannot select one through this endpoint.",
        "responses": {
          "200": {
            "description": "Workspace context",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkspaceContext"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "x-authentication": "Requires the signed-in browser session; Supabase manages the actual cookies."
      }
    },
    "/api/workspace/roster": {
      "get": {
        "operationId": "searchWorkspaceRoster",
        "tags": [
          "Workspace"
        ],
        "summary": "Search the active team roster",
        "description": "Searches active employees by name, title, or department and returns at most eight matches. Managers are limited to their primary direct reports. An empty search returns an empty list. Some empty manager results omit role.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Search text. Empty input returns no employees.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching employees",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Roster"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "500": {
            "$ref": "#/components/responses/Error"
          }
        },
        "x-authentication": "Requires the signed-in browser session; Supabase manages the actual cookies."
      }
    },
    "/api/auth/sign-in": {
      "post": {
        "operationId": "requestSignInLink",
        "tags": [
          "Authentication"
        ],
        "summary": "Request a sign-in link",
        "description": "Sends a secure sign-in link to the supplied email when sign-in and mail delivery are configured. This initiates an interactive browser sign-in; it does not issue an API key or return a session token.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "next": {
                    "type": "string",
                    "description": "Optional local path to visit after sign-in. Invalid paths fall back to /app."
                  }
                }
              },
              "example": {
                "email": "person@example.com",
                "next": "/app"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sign-in link sent",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "Error": {
        "description": "Request could not be completed",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "WorkspaceContext": {
        "type": "object",
        "required": [
          "mode",
          "organization",
          "viewer"
        ],
        "properties": {
          "mode": {
            "type": "string",
            "enum": [
              "live",
              "preview",
              "impersonation"
            ]
          },
          "impersonation": {
            "type": "object",
            "nullable": true,
            "additionalProperties": true
          },
          "preview": {
            "type": "object",
            "additionalProperties": true
          },
          "organization": {
            "type": "object",
            "required": [
              "id",
              "name",
              "logoUrl"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "logoUrl": {
                "type": "string",
                "nullable": true
              }
            }
          },
          "viewer": {
            "type": "object",
            "required": [
              "id",
              "fullName",
              "title",
              "role"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "fullName": {
                "type": "string",
                "nullable": true
              },
              "title": {
                "type": "string",
                "nullable": true
              },
              "role": {
                "type": "string"
              }
            }
          },
          "platformUser": {
            "type": "object",
            "additionalProperties": true
          },
          "targets": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        }
      },
      "Roster": {
        "type": "object",
        "required": [
          "employees"
        ],
        "properties": {
          "employees": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "full_name",
                "title",
                "department"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "full_name": {
                  "type": "string"
                },
                "title": {
                  "type": "string",
                  "nullable": true
                },
                "department": {
                  "type": "string",
                  "nullable": true
                }
              }
            }
          },
          "role": {
            "type": "string",
            "description": "Viewer role, when returned."
          }
        }
      }
    }
  }
}
