{
  "openapi": "3.1.1",
  "info": {
    "title": "SYNQENTIS BUSINESS — import-to-report contract",
    "version": "1.0.0-portfolio",
    "description": "Selected existing API flow reconstructed from source revision ad1efec7e5f33e6dd064cbb6146a2ecf539c94cd. Not the entire application API. Examples show a documented subset of the actual response fields; additional properties are retained. No live calls are made by the documentation page."
  },
  "servers": [
    {
      "url": "https://synqentis-business-pg-qa.onrender.com",
      "description": "QA only. Authentication required; never use production for this demonstration."
    }
  ],
  "tags": [
    {
      "name": "Import and reporting",
      "description": "CSV → validation → confirmation → metrics → saved snapshot"
    }
  ],
  "paths": {
    "/api/workspace/projects": {
      "get": {
        "operationId": "listProjects",
        "summary": "listProjects",
        "description": "",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "projects": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Project"
                      }
                    }
                  },
                  "required": [],
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": []
      },
      "post": {
        "operationId": "createProject",
        "summary": "createProject",
        "description": "Owner/admin. A non-empty trimmed name is required.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Project"
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, mapping, rows or token. Inspect error/errors; correct the source before retrying.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "CSRF validation failed on a write request, or role cannot write this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Quota, limit or conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Must match the authenticated session CSRF value; the readable csrf cookie is issued at sign-in."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProjectInput"
              }
            }
          }
        }
      }
    },
    "/api/workspace/projects/{projectId}/summary": {
      "get": {
        "operationId": "getProjectSummary",
        "summary": "getProjectSummary",
        "description": "All authenticated project roles can read their own project summary. No role-based 403 is added to this GET route. Financial values can be null when unavailable.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Summary"
                },
                "example": {
                  "revenue": 80,
                  "soldCost": 30,
                  "profit": 50,
                  "margin": 62.5,
                  "purchases": 150,
                  "stockValue": 120,
                  "exact": {
                    "revenue": "80.00",
                    "soldCost": "30.00",
                    "profit": "50.00",
                    "margin": "62.50",
                    "purchases": "150.00",
                    "stockValue": "120.00"
                  },
                  "stock": [
                    {
                      "sku": "DEMO-TEA",
                      "stock": 8,
                      "available": 8,
                      "unitCost": 15,
                      "value": 120
                    }
                  ],
                  "finance": {
                    "asOf": "2026-11-29",
                    "receivables": null,
                    "payables": null,
                    "overdueReceivables": null,
                    "overduePayables": null
                  }
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project/resource unavailable in the current organisation, or operation unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          }
        ]
      }
    },
    "/api/workspace/projects/{projectId}/documents": {
      "get": {
        "operationId": "listDocuments",
        "summary": "listDocuments",
        "description": "",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "documents": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Document"
                      }
                    }
                  },
                  "required": [],
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project/resource unavailable in the current organisation, or operation unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          }
        ]
      },
      "post": {
        "operationId": "uploadDocument",
        "summary": "uploadDocument",
        "description": "Owner/admin; JSON base64 upload. The original file is limited to 4 MiB, with additional quota/queue checks. Upload stores the document; it does not post movements.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Document"
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, mapping, rows or token. Inspect error/errors; correct the source before retrying.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "CSRF validation failed on a write request, or role cannot write this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project/resource unavailable in the current organisation, or operation unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Quota, limit or conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Must match the authenticated session CSRF value; the readable csrf cookie is issued at sign-in."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Upload"
              }
            }
          }
        }
      }
    },
    "/api/workspace/projects/{projectId}/documents/{documentId}/preview": {
      "post": {
        "operationId": "previewDocument",
        "summary": "previewDocument",
        "description": "Owner/admin. Auto-mapping supports the control CSV with {}. Token expires in 10 minutes. Invalid rows must not yield a usable token.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Preview"
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, mapping, rows or token. Inspect error/errors; correct the source before retrying.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "CSRF validation failed on a write request, or role cannot write this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project/resource unavailable in the current organisation, or operation unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          },
          {
            "name": "documentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Must match the authenticated session CSRF value; the readable csrf cookie is issued at sign-in."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PreviewInput"
              }
            }
          }
        }
      }
    },
    "/api/import": {
      "post": {
        "operationId": "confirmImport",
        "summary": "confirmImport",
        "description": "Confirms the session organisation preview token. Used/expired tokens return 400. A fresh preview of duplicate movements may succeed with added=0 and skipped>0.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImportResult"
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, mapping, rows or token. Inspect error/errors; correct the source before retrying.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "CSRF validation failed on a write request, or role cannot write this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Must match the authenticated session CSRF value; the readable csrf cookie is issued at sign-in."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImportInput"
              }
            }
          }
        }
      }
    },
    "/api/workspace/projects/{projectId}/reports": {
      "get": {
        "operationId": "listSavedReports",
        "summary": "listSavedReports",
        "description": "",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "reports": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Report"
                      }
                    }
                  },
                  "required": [],
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project/resource unavailable in the current organisation, or operation unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          }
        ]
      },
      "post": {
        "operationId": "saveReport",
        "summary": "saveReport",
        "description": "Owner/admin/analyst can save. Observer falls through to 404 for this operation; 403 is still possible from the common write CSRF guard. A non-empty trimmed title is required.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Report"
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, mapping, rows or token. Inspect error/errors; correct the source before retrying.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "CSRF validation failed on a write request, or role cannot write this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project/resource unavailable in the current organisation, or operation unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Must match the authenticated session CSRF value; the readable csrf cookie is issued at sign-in."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReportInput"
              }
            }
          }
        }
      }
    },
    "/api/workspace/projects/{projectId}/reports/{reportId}": {
      "get": {
        "operationId": "getSavedReport",
        "summary": "getSavedReport",
        "description": "Returns the immutable saved snapshot, not a recalculation of current movements.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Report"
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project/resource unavailable in the current organisation, or operation unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          },
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          }
        ]
      }
    },
    "/api/workspace/projects/{projectId}/reports/{reportId}/pdf": {
      "get": {
        "operationId": "downloadSavedReportPdf",
        "summary": "downloadSavedReportPdf",
        "description": "",
        "responses": {
          "200": {
            "description": "Saved report bytes",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project/resource unavailable in the current organisation, or operation unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          },
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          },
          {
            "name": "lang",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "ru",
                "en"
              ],
              "default": "en"
            },
            "description": "Used by PDF rendering; omitted for Excel output."
          }
        ]
      }
    },
    "/api/workspace/projects/{projectId}/reports/{reportId}/excel": {
      "get": {
        "operationId": "downloadSavedReportExcel",
        "summary": "downloadSavedReportExcel",
        "description": "",
        "responses": {
          "200": {
            "description": "Saved report bytes",
            "content": {
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Session missing or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "451": {
            "description": "Current terms have not been accepted when legal enforcement is enabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Required PostgreSQL workspace or processing service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error. Do not blindly retry an import with an unknown outcome.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project/resource unavailable in the current organisation, or operation unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "tags": [
          "Import and reporting"
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          },
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          },
          {
            "name": "lang",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "ru",
                "en"
              ],
              "default": "en"
            },
            "description": "Used by PDF rendering; omitted for Excel output."
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {},
          "errors": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [],
        "additionalProperties": true
      },
      "Summary": {
        "type": "object",
        "properties": {
          "revenue": {
            "type": [
              "number",
              "null"
            ]
          },
          "soldCost": {
            "type": [
              "number",
              "null"
            ]
          },
          "profit": {
            "type": [
              "number",
              "null"
            ]
          },
          "margin": {
            "type": [
              "number",
              "null"
            ]
          },
          "purchases": {
            "type": [
              "number",
              "null"
            ]
          },
          "stockValue": {
            "type": [
              "number",
              "null"
            ]
          },
          "exact": {
            "type": "object",
            "properties": {
              "revenue": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^-?\\d+\\.\\d{2}$"
              },
              "soldCost": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^-?\\d+\\.\\d{2}$"
              },
              "profit": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^-?\\d+\\.\\d{2}$"
              },
              "margin": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^-?\\d+\\.\\d{2}$"
              },
              "purchases": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^-?\\d+\\.\\d{2}$"
              },
              "stockValue": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^-?\\d+\\.\\d{2}$"
              }
            },
            "required": [],
            "additionalProperties": true
          },
          "stock": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "sku": {
                  "type": "string"
                },
                "stock": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "available": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "unitCost": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "value": {
                  "type": [
                    "number",
                    "null"
                  ]
                }
              },
              "required": [],
              "additionalProperties": true
            }
          },
          "finance": {
            "type": "object",
            "properties": {
              "asOf": {
                "type": "string",
                "format": "date"
              },
              "receivables": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "payables": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "overdueReceivables": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "overduePayables": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [],
            "additionalProperties": true
          }
        },
        "required": [
          "revenue",
          "soldCost",
          "profit",
          "margin",
          "exact",
          "stock",
          "finance"
        ],
        "additionalProperties": true
      },
      "ProjectInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 100
          }
        },
        "required": [
          "name"
        ],
        "additionalProperties": true
      },
      "Project": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "name": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "name"
        ],
        "additionalProperties": true
      },
      "Upload": {
        "type": "object",
        "properties": {
          "filename": {
            "type": "string",
            "description": "Extension determines the parser; original bytes limited to 4 MiB."
          },
          "base64": {
            "type": "string",
            "contentEncoding": "base64"
          }
        },
        "required": [
          "filename",
          "base64"
        ],
        "additionalProperties": true
      },
      "Document": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "filename": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "filename"
        ],
        "additionalProperties": true
      },
      "PreviewInput": {
        "type": "object",
        "properties": {
          "table": {
            "type": "integer",
            "minimum": 0,
            "default": 0
          },
          "mapping": {
            "type": "object",
            "properties": {
              "date": {
                "type": "integer",
                "minimum": 0
              },
              "kind": {
                "type": "integer",
                "minimum": 0
              },
              "sku": {
                "type": "integer",
                "minimum": 0
              },
              "qty": {
                "type": "integer",
                "minimum": 0
              },
              "price": {
                "type": "integer",
                "minimum": 0
              }
            },
            "required": [],
            "additionalProperties": true
          },
          "kind": {
            "type": "string"
          },
          "reviewedCsv": {
            "type": "string",
            "maxLength": 100000,
            "description": "Only for reviewed text documents without extracted tables."
          }
        },
        "required": [],
        "additionalProperties": true
      },
      "Preview": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "rows": {
            "type": "integer",
            "minimum": 1
          },
          "preview": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        },
        "required": [
          "token",
          "rows",
          "preview"
        ],
        "additionalProperties": true
      },
      "ImportInput": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          }
        },
        "required": [
          "token"
        ],
        "additionalProperties": true
      },
      "ImportResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "added": {
            "type": "integer",
            "minimum": 0
          },
          "skipped": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "ok"
        ],
        "additionalProperties": true
      },
      "ReportInput": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "maxLength": 120
          }
        },
        "required": [
          "title"
        ],
        "additionalProperties": true
      },
      "Report": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "title": {
            "type": "string"
          },
          "snapshot": {
            "$ref": "#/components/schemas/Summary"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [],
        "additionalProperties": true
      }
    },
    "securitySchemes": {
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "sid",
        "description": "HttpOnly session cookie. sid and readable csrf are issued on sign-in; session TTL is 12 hours in this pinned source."
      }
    }
  },
  "x-source-revision": "ad1efec7e5f33e6dd064cbb6146a2ecf539c94cd",
  "x-source-files": [
    "app/server.mjs",
    "app/workspace-api.mjs",
    "app/business-report.mjs",
    "app/calc.mjs",
    "app/document-formats.mjs"
  ],
  "externalDocs": {
    "description": "OpenAPI 3.1.1 specification",
    "url": "https://spec.openapis.org/oas/v3.1.1.html"
  }
}