{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/luckpanda-app/json-schema/luckpanda-app-upsert-party-command-schema.json",
  "title": "UpsertPartyCommand",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/luckpanda-app-parties-api-openapi.yml#/components/schemas/UpsertPartyCommand",
  "allOf": [
    {
      "$ref": "#/$defs/CommandBase"
    },
    {
      "type": "object",
      "required": [
        "display_name"
      ],
      "properties": {
        "display_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "kind": {
          "type": "string",
          "enum": [
            "organization",
            "person"
          ]
        },
        "roles": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": [
              "customer",
              "vendor",
              "lead"
            ]
          }
        }
      }
    },
    {
      "$ref": "#/$defs/PartyProfile"
    }
  ],
  "$defs": {
    "AddressIn": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 1000
        },
        {
          "type": "object",
          "required": [
            "line1"
          ],
          "properties": {
            "line1": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "line2": {
              "type": [
                "string",
                "null"
              ]
            },
            "city": {
              "type": [
                "string",
                "null"
              ]
            },
            "state_code": {
              "type": [
                "string",
                "null"
              ],
              "pattern": "^[0-9]{2}$"
            },
            "postal_code": {
              "type": [
                "string",
                "null"
              ]
            },
            "country_code": {
              "type": [
                "string",
                "null"
              ],
              "pattern": "^[A-Z]{2}$"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "CommandBase": {
      "type": "object",
      "required": [
        "idempotency_key",
        "correlation_id"
      ],
      "properties": {
        "idempotency_key": {
          "$ref": "#/$defs/IdempotencyKey"
        },
        "correlation_id": {
          "$ref": "#/$defs/Uuid"
        },
        "dry_run": {
          "type": "boolean",
          "default": false
        },
        "proposal_only": {
          "type": "boolean",
          "default": false,
          "description": "Make it a proposal for a person to accept instead of acting."
        },
        "approval_request_id": {
          "$ref": "#/$defs/Uuid"
        }
      }
    },
    "IdempotencyKey": {
      "type": "string",
      "minLength": 16,
      "maxLength": 128,
      "pattern": "^[A-Za-z0-9._:-]+$"
    },
    "PartyProfile": {
      "description": "Client profile (D91). Omitted keeps, null clears (on update). additionalProperties is checked on the merged command.",
      "type": "object",
      "properties": {
        "contact_name": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 200
        },
        "email": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 320
        },
        "phone": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 30
        },
        "billing_address": {
          "$ref": "#/$defs/AddressIn"
        },
        "shipping_address": {
          "$ref": "#/$defs/AddressIn"
        },
        "country_code": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[A-Z]{2}$"
        },
        "state_code": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9]{2}$",
          "description": "India GST state code; defaults to the GSTIN prefix."
        },
        "tax_id": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 100,
          "description": "GSTIN (validated) for India; VAT or other tax number elsewhere. Unique per business."
        },
        "currency": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[A-Z]{3}$"
        },
        "payment_terms_days": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "maximum": 365
        },
        "notes": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 4000
        }
      }
    },
    "Uuid": {
      "type": "string",
      "format": "uuid"
    }
  }
}