{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/conduyt-com/json-schema/conduyt-com-deal-update-schema.json",
  "title": "DealUpdate",
  "x-generated": "2026-10-30",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/conduyt-com-openapi.yaml#/components/schemas/DealUpdate",
  "type": "object",
  "properties": {
    "keepPreviousOwnerAsCollaborator": {
      "description": "With assignedTo set to another user: keep the previous owner as a collaborator of the deal's contact (read-only access to the lead and its cards) instead of releasing them. Default false. Cannot be combined with a contactId change. true needs assignedTo set to a user (the new owner) in the same request; otherwise a 400.",
      "type": "boolean"
    },
    "source": {
      "description": "Lead source of THIS opportunity (e.g. the campaign/trigger that produced it) — distinct from the contact's first-touch source. Cannot be cleared: every deal keeps a source. Leading and trailing whitespace is trimmed before the length check, so a blank value is refused.",
      "type": "string",
      "minLength": 1,
      "maxLength": 500
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "contactId": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
        },
        {
          "type": "null"
        },
        {
          "type": "string",
          "const": ""
        }
      ],
      "description": "An empty string is read as null before validation (it clears the field)."
    },
    "companyId": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
        },
        {
          "type": "null"
        }
      ]
    },
    "pipelineId": {
      "type": "string",
      "format": "uuid",
      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    },
    "stageId": {
      "type": "string",
      "format": "uuid",
      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    },
    "value": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "string",
          "pattern": "^-?\\d+(\\.\\d+)?$"
        },
        {
          "type": "null"
        }
      ],
      "description": "After rounding to 2 decimals the absolute value is at most 9999999999.99 (the Decimal(12,2) column); a larger value is a 400."
    },
    "currency": {
      "description": "ISO 4217 currency code (e.g. GBP). Omitting it leaves the existing deal currency unchanged.",
      "type": "string",
      "maxLength": 10
    },
    "status": {
      "type": "string",
      "enum": [
        "open",
        "won",
        "lost"
      ]
    },
    "priority": {
      "type": "string",
      "maxLength": 30
    },
    "probability": {
      "description": "Win probability as a 0–1 fraction (e.g. 0.75 = 75%), not a percentage",
      "anyOf": [
        {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        {
          "type": "null"
        }
      ]
    },
    "expectedCloseDate": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 50
        },
        {
          "type": "null"
        }
      ],
      "description": "An empty string is read as null before validation (it clears the field). An ISO 8601 date (YYYY-MM-DD) or date-time; an impossible calendar value or anything else is refused."
    },
    "appointmentAt": {
      "description": "Appointment date/time for THIS deal (ISO 8601 with offset), pushed by the external booking/AI layer. Drives the missed-appointment clock. Send null or \"\" to clear. An empty string is read as null before validation (it clears the field). Must lie between 2020-01-01T00:00:00.000Z and 5 calendar years from now; a value outside the window is refused.",
      "anyOf": [
        {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$",
          "description": "The pattern above is the server's rule (Zod's ISO date-time check). It also accepts minute precision without seconds (2026-12-01T10:00Z), which an RFC 3339 `format: date-time` validator refuses; send seconds for portability."
        },
        {
          "type": "null"
        },
        {
          "type": "string",
          "const": ""
        }
      ]
    },
    "assignedTo": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
        },
        {
          "type": "null"
        },
        {
          "type": "string",
          "const": ""
        }
      ],
      "description": "An empty string is read as null before validation (it clears the field)."
    },
    "lostReason": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 500
        },
        {
          "type": "null"
        }
      ]
    },
    "closeDate": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 50
        },
        {
          "type": "null"
        }
      ],
      "description": "A real calendar date (YYYY-MM-DD) or ISO 8601 date-time; anything else is a 400."
    },
    "expectedUpdatedAt": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$",
      "description": "Optional optimistic-concurrency pin: the deal's `updatedAt` as the caller last read it. When it no longer matches, the request is refused with 409 `code: \"deal_changed\"` and nothing is written. Omit it for last-write-wins per field. The pattern above is the server's rule (Zod's ISO date-time check). It also accepts minute precision without seconds (2026-12-01T10:00Z), which an RFC 3339 `format: date-time` validator refuses; send seconds for portability."
    },
    "expectedStageId": {
      "type": "string",
      "format": "uuid",
      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
      "description": "The stage the caller's move was chosen against: refused with 409 (nothing written) when the deal is no longer in it."
    },
    "checkOrigin": {
      "type": "string",
      "enum": [
        "stale",
        "unassigned",
        "missing_close_date",
        "missing_contact"
      ],
      "description": "Pipeline health quick fix: the health check this edit fixes. The body must be exactly that check's fix and `expectedUpdatedAt`: stale = `stageId` (+ optional `expectedStageId`), unassigned = `assignedTo`, missing_close_date = `expectedCloseDate`, missing_contact = `contactId`, each set to a value; anything else is a 400 `health_fix_mismatch` (nothing read or written). A deal at another version is refused with 409 `deal_changed`, one that no longer fails the check with 409 `deal_check_cleared`, both carrying the deal's current health row (HealthFixRefusal)."
    },
    "customFields": {
      "type": "object",
      "additionalProperties": {},
      "description": "Patch semantics per key: the keys sent replace those keys (send null to clear one); keys not sent keep their current values, including values written by another writer while this request was in flight. At most 65536 bytes (64 KiB) as UTF-8 JSON (JSON.stringify of the object); a larger object is refused (413)."
    },
    "products": {
      "maxItems": 50,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "description": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 1000
              },
              {
                "type": "null"
              }
            ]
          },
          "quantity": {
            "default": 1,
            "type": "integer",
            "minimum": 1,
            "maximum": 999999
          },
          "unitPrice": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              }
            ],
            "description": "After rounding to 2 decimals the absolute value is at most 9999999999.99 (the Decimal(12,2) column); a larger value is a 400."
          },
          "discount": {
            "default": 0,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              }
            ],
            "description": "After rounding to 2 decimals the absolute value is at most 9999999999.99 (the Decimal(12,2) column); a larger value is a 400."
          },
          "tax": {
            "default": 0,
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string",
                "pattern": "^-?\\d+(\\.\\d+)?$"
              }
            ],
            "description": "After rounding to 2 decimals the absolute value is at most 9999999999.99 (the Decimal(12,2) column); a larger value is a 400."
          },
          "sortOrder": {
            "type": "integer",
            "minimum": 0,
            "maximum": 999
          }
        },
        "required": [
          "name",
          "unitPrice"
        ],
        "description": "Each line's total (quantity x unitPrice - discount + tax) must fit the Decimal(12,2) column too (at most 9999999999.99 in absolute value); otherwise a 400."
      }
    },
    "sortOrder": {
      "type": "integer",
      "minimum": -2147483648,
      "maximum": 2147483647,
      "description": "Kanban column sort position"
    }
  }
}