{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/akeda-ru/json-schema/akeda-ru-finance-operation-accrual-create-schema.json",
  "title": "FinanceOperationAccrualCreate",
  "description": "Указывает ровно одну цель распределения: accrual_id для одной части плана либо allocations для нескольких частей. Совместимость этого ограничения проверяет сервер; плоская форма сохранена, чтобы сгенерированные TypeScript- и Swift-клиенты не теряли общие поля.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/akeda-ru-app-runtime-api-openapi.yml#/components/schemas/FinanceOperationAccrualCreate",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "source",
    "expected_version",
    "date",
    "amount"
  ],
  "properties": {
    "source": {
      "$ref": "#/$defs/FinanceOperationSource"
    },
    "expected_version": {
      "type": "integer",
      "minimum": 1
    },
    "accrual_id": {
      "$ref": "#/$defs/UUID"
    },
    "allocations": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "items": {
        "$ref": "#/$defs/FinanceOperationAccrualAllocation"
      }
    },
    "date": {
      "type": "string",
      "format": "date"
    },
    "amount": {
      "type": "string",
      "description": "Сумма документа; должна совпасть с суммой allocations"
    },
    "due_date": {
      "type": "string",
      "format": "date",
      "description": "Обычно вычисляется из графика; переданное значение не может ему противоречить"
    },
    "reason": {
      "type": "string"
    },
    "vat_amount": {
      "type": "string",
      "description": "Только закупка без «в т.ч. НДС» на плане (ERP-484, подшаг 5.3в): «в т.ч. НДС» акта поставщика. Обязательна, если на дату начисления бизнес очищает суммы и юрлицо принимает налог к вычету; 0 — налог не выделен. У плана с налогом начисление берёт долю нарастающим итогом, и непустое значение — 400"
    },
    "supplier_document": {
      "$ref": "#/$defs/SupplierDocument"
    }
  },
  "$defs": {
    "FinanceOperationAccrualAllocation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "accrual_id",
        "amount"
      ],
      "properties": {
        "accrual_id": {
          "$ref": "#/$defs/UUID"
        },
        "amount": {
          "type": "string",
          "description": "Положительная decimal string"
        }
      }
    },
    "FinanceOperationSource": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schema_version",
        "source_system",
        "source_ref",
        "external_id",
        "idempotency_key"
      ],
      "properties": {
        "schema_version": {
          "type": "integer",
          "enum": [
            1
          ]
        },
        "source_system": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "source_ref": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "external_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "idempotency_key": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        }
      }
    },
    "SupplierDocument": {
      "type": "object",
      "additionalProperties": false,
      "description": "Номер и дата документа поставщика (ERP-484, подшаг 5.3): по ним входящий НДС сверяется с книгой покупок. Оба поля необязательны",
      "properties": {
        "number": {
          "type": "string",
          "maxLength": 100
        },
        "date": {
          "type": "string",
          "format": "date"
        }
      }
    },
    "UUID": {
      "type": "string",
      "format": "uuid"
    }
  }
}