{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/conduyt-com/json-schema/conduyt-com-deal-create-schema.json",
  "title": "DealCreate",
  "x-generated": "2026-10-30",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/conduyt-com-openapi.yaml#/components/schemas/DealCreate",
  "type": "object",
  "required": [
    "title",
    "pipelineId",
    "stageId"
  ],
  "properties": {
    "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",
      "minLength": 1,
      "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",
      "minLength": 1,
      "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). Backend defaults to USD when omitted.",
      "type": "string",
      "maxLength": 10
    },
    "status": {
      "type": "string",
      "enum": [
        "open",
        "won",
        "lost"
      ]
    },
    "priority": {
      "type": "string",
      "maxLength": 30
    },
    "source": {
      "description": "Lead source of THIS opportunity (e.g. the campaign/trigger that produced it) — distinct from the contact's first-touch source Leading and trailing whitespace is trimmed before the length check, so a blank value is refused.",
      "anyOf": [
        {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        {
          "type": "null"
        }
      ]
    },
    "lostReason": {
      "description": "Reason for a lost/disqualified deal. Required when creating directly into a stage that mandates one; constrained stages only accept their configured options (the 422 lists them).",
      "anyOf": [
        {
          "type": "string",
          "maxLength": 500
        },
        {
          "type": "null"
        }
      ]
    },
    "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)."
    },
    "customFields": {
      "type": "object",
      "additionalProperties": {},
      "description": "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."
      }
    }
  }
}