{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/cosuno/json-schema/cosuno-create-review-requests-input-schema.json",
  "title": "CreateReviewRequestsInput",
  "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/CreateReviewRequestsInput",
  "properties": {
    "subcontractorId": {
      "type": "string",
      "description": "ID of the subcontractor being reviewed."
    },
    "object": {
      "anyOf": [
        {
          "$ref": "#/$defs/BidPackageLinkedReviewObjectInput"
        },
        {
          "$ref": "#/$defs/IndependentReviewObjectInput"
        }
      ],
      "description": "The object the reviews are about. Either a bid package the subcontractor has been invited to, or an independent object with name."
    },
    "assignments": {
      "items": {
        "$ref": "#/$defs/ReviewAssignmentInput"
      },
      "type": "array",
      "description": "Templates to request reviews for. Each entry pairs a template with the reviewers who should fill it in.",
      "minItems": 1
    },
    "sequential": {
      "type": "boolean",
      "description": "When `true`, reviewers are notified one step at a time. Step N+1 starts once every reviewer in step N has submitted or has been auto-skipped after a period of inactivity."
    }
  },
  "required": [
    "subcontractorId",
    "object",
    "assignments"
  ],
  "type": "object",
  "additionalProperties": false,
  "$defs": {
    "BidPackageLinkedReviewObjectInput": {
      "description": "Links the review to a bid package the subcontractor has been invited to.",
      "properties": {
        "bidPackageId": {
          "type": "string",
          "description": "Unique identifier of the bid package. The subcontractor must already have been invited to bid on it."
        }
      },
      "required": [
        "bidPackageId"
      ],
      "type": "object",
      "additionalProperties": false
    },
    "IndependentReviewObjectInput": {
      "description": "Links the review to an object outside of Cosuno (e.g. a contract managed in your ERP).",
      "properties": {
        "name": {
          "type": "string",
          "description": "Human-readable name of the object the review is about.",
          "maxLength": 150
        },
        "externalId": {
          "type": "string",
          "description": "Optional identifier from your external system. Must be unique per company. Reusing the same `externalId` on subsequent calls for the same subcontractor aggregates the reviews under one object; the latest `name` overwrites the stored one. Without an `externalId`, each call creates a new object.",
          "maxLength": 255
        }
      },
      "required": [
        "name"
      ],
      "type": "object",
      "additionalProperties": false
    },
    "ReviewAssignmentInput": {
      "properties": {
        "templateId": {
          "type": "string",
          "description": "ID of the review template the reviewers should fill in."
        },
        "reviewerIds": {
          "items": {
            "type": "string"
          },
          "type": "array",
          "description": "IDs of the users to ask for reviews. Reviewers must be active users of the same company as the caller.",
          "minItems": 1
        },
        "step": {
          "type": "number",
          "format": "double",
          "description": "Required when `sequential` is `true`. 1-indexed position of this template in the dispatch order; values must be unique and contiguous across assignments.",
          "minimum": 1
        }
      },
      "required": [
        "templateId",
        "reviewerIds"
      ],
      "type": "object",
      "additionalProperties": false
    }
  }
}