"/admin/fabricator/schemas":
    get:
        tags: [Fabricator Scans]
        operationId: getFabricatorSchemas
        summary: Fabricator schema enumerations (v1)
        description: Returns enumerations consumed by the manufacturing pipeline (job states, scan-request states, etc.).
        responses:
            "200":
                description: Schema enumeration payload.
                content:
                    application/json:
                        schema:
                            type: object
                            additionalProperties:
                                type: array
                                items: { type: string }
                            description: Each top-level key is an enum name; the value is the list of legal members.
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Inventory, CncMachine, Fabricator]
        x-scopes: ["fabricator:read", "admin:all"]

"/admin/fabricator/schemas2":
    get:
        tags: [Fabricator Scans]
        operationId: getFabricatorSchemas2
        summary: Fabricator schema enumerations (v2)
        description: |
            V2 of `/admin/fabricator/schemas` — also includes BigOrder-related schemas. Prefer
            this over v1 for new integrations.
        responses:
            "200":
                description: V2 schema enumeration payload.
                content:
                    application/json:
                        schema:
                            type: object
                            additionalProperties:
                                type: array
                                items: { type: string }
                            description: Each top-level key is an enum name; the value is the list of legal members.
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Inventory, CncMachine, Fabricator]
        x-scopes: ["fabricator:read", "admin:all"]

"/admin/fabricator/scan_requests":
    get:
        tags: [Fabricator Scans]
        operationId: getScanRequests
        summary: List all scan requests
        description: Returns every scan request known to the system.
        responses:
            "200":
                description: Array of scan requests.
                content:
                    application/json:
                        schema:
                            type: array
                            items: { $ref: "../components/schemas/ScanRequest.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Admin]
        x-scopes: ["fabricator:read", "admin:all"]

"/admin/fabricator/scan_requests/repair":
    get:
        tags: [Fabricator Scans]
        operationId: repairScanRequests
        summary: Repair scan requests
        description: Walks the scan-request table and repairs any rows that have drifted out of a consistent state. Idempotent.
        responses:
            "200":
                description: Repair summary.
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                scanRequestsExamined: { type: integer }
                                scanRequestsRepaired: { type: integer }
                                durationMs: { type: integer }
                                errors:
                                    type: array
                                    items: { type: string }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Admin]
        x-scopes: ["fabricator:read", "admin:all"]

"/admin/fabricator/account/{bigscreenAccountId}/scan_requests":
    parameters:
        - in: path
          name: bigscreenAccountId
          required: true
          schema: { type: string }
    get:
        tags: [Fabricator Scans]
        operationId: getScanRequestsForAccount
        summary: List scan requests for an account
        description: Returns scan requests submitted by the supplied Bigscreen account.
        responses:
            "200":
                description: Array of scan requests.
                content:
                    application/json:
                        schema:
                            type: array
                            items: { $ref: "../components/schemas/ScanRequest.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
        x-access-policies: [Fabricator]
        x-scopes: ["fabricator:read", "admin:all"]

"/admin/fabricator/account/{bigscreenAccountId}/scan_data":
    parameters:
        - in: path
          name: bigscreenAccountId
          required: true
          schema: { type: string }
    delete:
        tags: [Fabricator Scans]
        operationId: deleteScanDataGDPR
        summary: GDPR — delete scan data for an account
        description: |
            Deletes (or, in dry-run mode, reports on) all scan data the system holds for the
            supplied Bigscreen account. Used to satisfy GDPR right-to-erasure requests.
            Returns the inventory of what was found / deleted.
        parameters:
            - in: query
              name: dryRun
              required: false
              schema: { type: string, enum: ["1"] }
              description: If set, returns the data inventory without deleting anything.
        responses:
            "200":
                description: Deletion (or dry-run inventory) result.
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                bigscreenAccountId: { type: string }
                                dryRun: { type: boolean }
                                scanRequestsFound: { type: integer }
                                scanRequestsDeleted: { type: integer }
                                jobsFound: { type: integer }
                                jobsDeleted: { type: integer }
                                scanFilesDeleted: { type: integer }
                                meshFilesDeleted: { type: integer }
                                durationMs: { type: integer }
                                errors:
                                    type: array
                                    items: { type: string }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "422":
                description: Missing or invalid `bigscreenAccountId`.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [Fabricator]
        x-scopes: ["fabricator:write", "admin:all"]

"/admin/fabricator/scan_request/{scanRequestId}":
    parameters:
        - in: path
          name: scanRequestId
          required: true
          schema: { type: string }
    get:
        tags: [Fabricator Scans]
        operationId: getScanRequest
        summary: Fetch a scan request
        description: Returns a single scan request by id.
        responses:
            "200":
                description: Scan request.
                content:
                    application/json:
                        schema: { $ref: "../components/schemas/ScanRequest.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No scan request with this id.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [Fabricator]
        x-scopes: ["fabricator:read", "admin:all"]
    put:
        tags: [Fabricator Scans]
        operationId: updateScanRequest
        summary: Update a scan request
        description: Updates a scan request (state transitions, IPD overrides, etc.).
        requestBody:
            required: true
            content:
                application/json:
                    schema:
                        type: object
                        additionalProperties: true
        responses:
            "200":
                description: Updated scan request.
                content:
                    application/json:
                        schema: { $ref: "../components/schemas/ScanRequest.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No scan request with this id.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [Fabricator]
        x-scopes: ["fabricator:write", "admin:all"]
    delete:
        tags: [Fabricator Scans]
        operationId: deleteScanRequest
        summary: Delete a scan request
        description: Hard-deletes a scan request. Restricted to `Admin`.
        responses:
            "200":
                description: Scan request deleted.
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No scan request with this id.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [Admin]
        x-scopes: ["fabricator:write", "admin:all"]

"/admin/fabricator/scan_request/{scanRequestId}/topology/{topologyPatientIdOverride}":
    parameters:
        - in: path
          name: scanRequestId
          required: true
          schema: { type: string }
        - in: path
          name: topologyPatientIdOverride
          required: true
          schema: { type: string }
          description: |
              Patient-id override forwarded to Topology. The trailing override segment is
              technically optional in the registered route (`/topology{/:topologyPatientIdOverride}`);
              when omitted, the original patient id is used.
    get:
        tags: [Fabricator Scans]
        operationId: updateScanRequestWithTopologyScan
        summary: Update a scan request with Topology data
        description: |
            Updates the scan request with data pulled from the Topology service. The
            `topologyPatientIdOverride` segment is optional in the underlying route.
        responses:
            "200":
                description: Updated scan request.
                content:
                    application/json:
                        schema: { $ref: "../components/schemas/ScanRequest.yaml" }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No scan request with this id.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [FabricatorAdmin]
        x-scopes: ["fabricator:read", "admin:all"]

"/admin/fabricator/scan_request/{scanRequestId}/scan":
    parameters:
        - in: path
          name: scanRequestId
          required: true
          schema: { type: string }
    get:
        tags: [Fabricator Scans]
        operationId: getScanRequestScanFile
        summary: Download the scan file
        description: Downloads the raw scan file uploaded for this scan request.
        responses:
            "200":
                description: Scan file.
                content:
                    application/zip:
                        schema:
                            type: string
                            format: binary
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No scan file for this request.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [FabricatorAdmin]
        x-scopes: ["fabricator:read", "admin:all"]

"/admin/fabricator/scan_request/{scanRequestId}/verify":
    parameters:
        - in: path
          name: scanRequestId
          required: true
          schema: { type: string }
    get:
        tags: [Fabricator Scans]
        operationId: verifyScanRequest
        summary: Verify a scan request
        description: Runs verification checks on a scan request and reports the result.
        responses:
            "200":
                description: Verification result.
                content:
                    application/json:
                        schema:
                            type: object
                            properties:
                                scanRequestId: { type: string }
                                verified: { type: boolean }
                                ipd: { type: integer }
                                preprocessorResult: { type: string }
                                issues:
                                    type: array
                                    items:
                                        type: object
                                        properties:
                                            severity: { type: string }
                                            code: { type: string }
                                            message: { type: string }
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No scan request with this id.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [Fabricator]
        x-scopes: ["fabricator:read", "admin:all"]

"/admin/fabricator/scan_request/{scanRequestId}/mesh":
    parameters:
        - in: path
          name: scanRequestId
          required: true
          schema: { type: string }
    get:
        tags: [Fabricator Scans]
        operationId: getScanRequestMesh
        summary: Download the mesh file
        description: Downloads the processed mesh file for the scan request.
        responses:
            "200":
                description: Mesh file.
                content:
                    application/octet-stream:
                        schema:
                            type: string
                            format: binary
            "401": { $ref: "../admin-api.yaml#/components/responses/Unauthorized" }
            "403": { $ref: "../admin-api.yaml#/components/responses/Forbidden" }
            "404":
                description: No mesh file for this request.
                content:
                    application/json:
                        schema: { $ref: "../admin-api.yaml#/components/schemas/Error" }
        x-access-policies: [FabricatorAdmin]
        x-scopes: ["fabricator:read", "admin:all"]
