{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/cosuno/json-schema/cosuno-review-request-response-schema.json",
  "title": "ReviewRequestResponse",
  "description": "A request asking a user to review a subcontractor. May be pending, dispatched, completed, or skipped — derive the state from the timestamps below.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/cosuno-subcontractor-reviews-api-openapi.yml#/components/schemas/ReviewRequestResponse",
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique identifier of the review request."
    },
    "createdAt": {
      "type": "string",
      "description": "Timestamp at which the request was created."
    },
    "dispatchedAt": {
      "type": [
        "string",
        "null"
      ],
      "description": "Timestamp at which the request was dispatched (notification sent to the reviewer). Non-sequential requests are dispatched immediately on creation. Sequential requests are dispatched only once all earlier steps have completed or been skipped, and stay `null` until then."
    },
    "completedAt": {
      "type": [
        "string",
        "null"
      ],
      "description": "Timestamp at which the reviewer submitted their review for this request, or `null` if not submitted yet."
    },
    "skippedAt": {
      "type": [
        "string",
        "null"
      ],
      "description": "Timestamp at which this request was auto-skipped after the dispatch period expired without a submission, or `null` otherwise."
    },
    "batchId": {
      "type": "string",
      "description": "Identifier shared by all requests that were created together in a single call. Groups sequential and parallel requests sent as one batch."
    },
    "step": {
      "type": [
        "number",
        "null"
      ],
      "format": "double",
      "description": "1-indexed step of this request within a sequential batch. `null` for non-sequential requests."
    },
    "subcontractor": {
      "$ref": "#/$defs/ReviewSubcontractorResponse",
      "description": "Subcontractor the request is about."
    },
    "object": {
      "$ref": "#/$defs/ReviewObjectResponse",
      "description": "Object the request is about."
    },
    "template": {
      "$ref": "#/$defs/ReviewTemplateResponse",
      "description": "Review template (questionnaire) the reviewer is asked to fill in."
    },
    "requestedBy": {
      "$ref": "#/$defs/UserResponse",
      "description": "User who created the request."
    },
    "reviewer": {
      "$ref": "#/$defs/UserResponse",
      "description": "User asked to fill in the review."
    }
  },
  "required": [
    "id",
    "createdAt",
    "dispatchedAt",
    "completedAt",
    "skippedAt",
    "batchId",
    "step",
    "subcontractor",
    "object",
    "template",
    "requestedBy",
    "reviewer"
  ],
  "type": "object",
  "additionalProperties": false,
  "$defs": {
    "BidPackageLinkedReviewObjectResponse": {
      "description": "Object under review, linked to a bid package in Cosuno.",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "bidPackage"
          ],
          "description": "Discriminator. Always `bidPackage` for this variant."
        },
        "bidRequestId": {
          "type": "string",
          "description": "ID of the bid request (subcontractor + bid package pair) the review/request is linked to."
        },
        "bidPackageId": {
          "type": "string",
          "description": "ID of the bid package the bid request belongs to."
        },
        "projectId": {
          "type": "string",
          "description": "ID of the project the bid package belongs to."
        }
      },
      "required": [
        "type",
        "bidRequestId",
        "bidPackageId",
        "projectId"
      ],
      "type": "object",
      "additionalProperties": false
    },
    "IndependentReviewObjectResponse": {
      "description": "Object under review, independent of any Cosuno bid package.",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "independent"
          ],
          "description": "Discriminator. Always `independent` for this variant."
        },
        "name": {
          "type": "string",
          "description": "Human-readable name of the object under review."
        },
        "externalId": {
          "type": "string",
          "description": "Identifier of the object in your external system, if any."
        }
      },
      "required": [
        "type",
        "name"
      ],
      "type": "object",
      "additionalProperties": false
    },
    "ReviewObjectResponse": {
      "anyOf": [
        {
          "$ref": "#/$defs/BidPackageLinkedReviewObjectResponse"
        },
        {
          "$ref": "#/$defs/IndependentReviewObjectResponse"
        }
      ],
      "description": "Object the review or request is about. Either tied to a Cosuno bid package, or an independent object identified by name (and optionally an external ID)."
    },
    "ReviewSubcontractorResponse": {
      "description": "Subcontractor the review or request is about.",
      "properties": {
        "id": {
          "type": "string",
          "description": "ID of the subcontractor."
        },
        "name": {
          "type": "string",
          "description": "Name of the subcontractor."
        },
        "externalSource": {
          "type": "string",
          "description": "Identifier of the external system this subcontractor was imported from, if any."
        },
        "externalId": {
          "type": "string",
          "description": "Identifier of this subcontractor within the external system, if any."
        }
      },
      "required": [
        "id",
        "name"
      ],
      "type": "object",
      "additionalProperties": false
    },
    "ReviewTemplateResponse": {
      "description": "Review template (questionnaire) the review or request uses.",
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique identifier of the review template."
        },
        "name": {
          "type": "string",
          "description": "Name of the review template."
        }
      },
      "required": [
        "id",
        "name"
      ],
      "type": "object",
      "additionalProperties": false
    },
    "USER_STATUS": {
      "type": "string",
      "enum": [
        "approvalPending",
        "adminApprovalPending",
        "invited",
        "inviteCanceled",
        "inviteFailed",
        "inviteRequested",
        "active",
        "inactive"
      ]
    },
    "USER_TYPE": {
      "type": "string",
      "enum": [
        "custom",
        "administrator",
        "employee",
        "guest",
        "collaborator",
        "manager"
      ]
    },
    "UserResponse": {
      "properties": {
        "id": {
          "type": "string",
          "description": "ID of the user."
        },
        "email": {
          "type": "string",
          "description": "Email address of the user. Also used as their login identifier."
        },
        "status": {
          "$ref": "#/$defs/USER_STATUS",
          "description": "Current status of the user."
        },
        "firstName": {
          "type": "string",
          "description": "Given name of the user."
        },
        "lastName": {
          "type": "string",
          "description": "Family name of the user."
        },
        "type": {
          "$ref": "#/$defs/USER_TYPE",
          "description": "Account type of the user. Values starting with `custom` indicate a custom user role (see `customUserRoleId`)."
        },
        "customUserRoleId": {
          "type": "string",
          "description": "ID of the custom user role assigned to the user. Present only when `type` refers to a custom user role."
        }
      },
      "required": [
        "id",
        "email",
        "status",
        "type"
      ],
      "type": "object",
      "additionalProperties": false
    }
  }
}