{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pachca.com/ai_legal/agent/schemas/input.schema.json",
  "title": "Pachca contract input",
  "description": "Filled input for either template. Source binding, real calendar dates, exact user confirmation and contractual rules are checked separately by the pinned filler. Blank collection forms deliberately do not pass.",
  "type": "object",
  "properties": {
    "template": {
      "enum": [
        "company",
        "corporation"
      ]
    },
    "contract_date": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
    },
    "licensee": {
      "type": "object"
    },
    "order": {},
    "sources": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "$ref": "#/$defs/evidence"
      }
    },
    "source_files": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/boundFile"
      }
    },
    "approval": {
      "type": "object",
      "properties": {
        "quote": {
          "type": [
            "string",
            "null"
          ]
        },
        "values": {
          "type": "object"
        }
      },
      "required": [
        "quote",
        "values"
      ],
      "additionalProperties": false
    },
    "changes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/change"
      }
    }
  },
  "required": [
    "template",
    "contract_date",
    "licensee",
    "order",
    "sources",
    "source_files",
    "approval",
    "changes"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "template": {
            "const": "company"
          }
        },
        "required": [
          "template"
        ]
      },
      "then": {
        "properties": {
          "licensee": {
            "type": "object",
            "properties": {
              "name_full": {
                "$ref": "#/$defs/text",
                "description": "Полное наименование организации с организационно-правовой формой, как в уставе"
              },
              "name_short": {
                "$ref": "#/$defs/text",
                "description": "Сокращённое наименование"
              },
              "signatory": {
                "$ref": "#/$defs/text",
                "description": "Должность и ФИО подписанта в форме, согласованной с пользователем для преамбулы"
              },
              "basis": {
                "$ref": "#/$defs/text",
                "description": "Основание полномочий подписанта в форме, согласованной для преамбулы"
              },
              "address": {
                "$ref": "#/$defs/text",
                "description": "Юридический адрес (место нахождения)"
              },
              "postal_address": {
                "$ref": "#/$defs/text",
                "description": "Почтовый адрес с индексом"
              },
              "inn": {
                "$ref": "#/$defs/text",
                "description": "ИНН лицензиата — перенести из источника как строку"
              },
              "kpp": {
                "$ref": "#/$defs/text",
                "description": "КПП, 9 знаков"
              },
              "ogrn": {
                "$ref": "#/$defs/text",
                "description": "ОГРН, 13 цифр"
              },
              "rs": {
                "$ref": "#/$defs/text",
                "description": "Расчётный счёт, 20 цифр; у организации, обслуживаемой Федеральным казначейством, — казначейский счёт 03…"
              },
              "ks": {
                "$ref": "#/$defs/text",
                "description": "Корреспондентский счёт банка, 20 цифр, начинается с 30101; у организации, обслуживаемой Федеральным казначейством, — единый казначейский счёт 40102…"
              },
              "bik": {
                "$ref": "#/$defs/text",
                "description": "БИК, 9 цифр: банка (04…) или органа Федерального казначейства (00…, 01…, 02… или 04…)"
              },
              "bank": {
                "$ref": "#/$defs/text",
                "description": "Наименование банка, как в карточке организации"
              },
              "auth_email": {
                "$ref": "#/$defs/text",
                "description": "Авторизованные адреса Лицензиата — поле в реквизитах договора; несколько адресов — через запятую"
              },
              "notify_email": {
                "$ref": "#/$defs/text",
                "description": "Адрес электронной почты для направления уведомлений"
              }
            },
            "required": [
              "name_full",
              "name_short",
              "signatory",
              "basis",
              "address",
              "postal_address",
              "inn",
              "kpp",
              "ogrn",
              "rs",
              "ks",
              "bik",
              "bank",
              "auth_email",
              "notify_email"
            ],
            "additionalProperties": false
          },
          "order": {
            "type": "null"
          }
        }
      },
      "else": {
        "properties": {
          "licensee": {
            "type": "object",
            "properties": {
              "name_full": {
                "$ref": "#/$defs/text",
                "description": "Полное наименование организации с организационно-правовой формой, как в уставе"
              },
              "address": {
                "$ref": "#/$defs/text",
                "description": "Юридический адрес (место нахождения)"
              },
              "postal_address": {
                "$ref": "#/$defs/text",
                "description": "Почтовый адрес с индексом"
              },
              "inn": {
                "$ref": "#/$defs/text",
                "description": "ИНН лицензиата — перенести из источника как строку"
              },
              "kpp": {
                "$ref": "#/$defs/text",
                "description": "КПП, 9 знаков"
              },
              "ogrn": {
                "$ref": "#/$defs/text",
                "description": "ОГРН, 13 цифр"
              },
              "rs": {
                "$ref": "#/$defs/text",
                "description": "Расчётный счёт, 20 цифр; у организации, обслуживаемой Федеральным казначейством, — казначейский счёт 03…"
              },
              "ks": {
                "$ref": "#/$defs/text",
                "description": "Корреспондентский счёт банка, 20 цифр, начинается с 30101; у организации, обслуживаемой Федеральным казначейством, — единый казначейский счёт 40102…"
              },
              "bik": {
                "$ref": "#/$defs/text",
                "description": "БИК, 9 цифр: банка (04…) или органа Федерального казначейства (00…, 01…, 02… или 04…)"
              },
              "bank": {
                "$ref": "#/$defs/text",
                "description": "Наименование банка, как в карточке организации"
              },
              "auth_email": {
                "$ref": "#/$defs/text",
                "description": "Авторизованные адреса Лицензиата — поле в реквизитах договора; несколько адресов — через запятую"
              },
              "notify_email": {
                "$ref": "#/$defs/text",
                "description": "Адрес электронной почты для направления уведомлений"
              },
              "domain": {
                "$ref": "#/$defs/text",
                "description": "Домен корпоративной почты без @ (определение «Авторизованный домен» в разделе 1)"
              }
            },
            "required": [
              "name_full",
              "address",
              "postal_address",
              "inn",
              "kpp",
              "ogrn",
              "rs",
              "ks",
              "bik",
              "bank",
              "auth_email",
              "notify_email",
              "domain"
            ],
            "additionalProperties": false
          },
          "order": {
            "type": "object",
            "properties": {
              "prepayment_months": {
                "$ref": "#/$defs/positiveInteger",
                "minimum": 3,
                "description": "Corporation requires upfront payment for at least 3 calendar months. Ask separately for the agreed prepayment period and its source. Do not infer it from the licence term or a price per month, and never silently replace 1 or 2 with 3. Neither changes nor confirmation bypasses this minimum. This field is included in the full confirmation; the standard Word template retains its existing minimum-payment clause."
              },
              "lines": {
                "type": "array",
                "minItems": 1,
                "maxItems": 3,
                "items": {
                  "$ref": "#/$defs/line"
                }
              }
            },
            "required": [
              "lines",
              "prepayment_months"
            ],
            "additionalProperties": false
          }
        }
      }
    }
  ],
  "$defs": {
    "text": {
      "type": "string",
      "minLength": 1,
      "maxLength": 8192
    },
    "multiline": {
      "type": "string",
      "minLength": 1,
      "maxLength": 65536
    },
    "positiveInteger": {
      "type": "integer",
      "minimum": 1,
      "maximum": 1000000000,
      "description": "Positive integer value. The pinned filler additionally requires an integer JSON literal: 3, not 3.0 or exponent notation."
    },
    "price": {
      "type": "string",
      "minLength": 1,
      "maxLength": 20,
      "pattern": "^[0-9]+(?:\\.[0-9]{1,2})?$",
      "description": "Roubles per licence per month, as a JSON string: \"100.50\". No comma, currency sign, silent conversion or rounding."
    },
    "line": {
      "type": "object",
      "properties": {
        "name": {
          "$ref": "#/$defs/text",
          "pattern": "^Лицензия на программу для ЭВМ «Пачка», тип «Корпорация», модуль «(?![!-/:-@\\[-`{-~\\s…–—]+»)[^«»\\s](?:[^«»]*[^«»\\s])?»(?: ?/ ?«(?![!-/:-@\\[-`{-~\\s…–—]+»)[^«»\\s](?:[^«»]*[^«»\\s])?»)*(?:, версия «(?![!-/:-@\\[-`{-~\\s…–—]+»)[^«»\\s](?:[^«»]*[^«»\\s])?»)?$",
          "description": "Use the full Russian name with program, licence type and agreed module, exactly as in the examples. A plan-only label or тариф instead of тип is rejected. Take each module and the optional version from agreed sources. A label made only of placeholder signs, such as ___, - or ..., is rejected; ask for its exact text. If only the module is known, show its full name and obtain verbatim confirmation as a separate source. If the module is missing, ask for it. Never expand the original quotation or guess a module. Other wording requires a separately marked editor draft under guide/05-changes.md; changes does not bypass this input check.",
          "examples": [
            "Лицензия на программу для ЭВМ «Пачка», тип «Корпорация», модуль «Администратор»",
            "Лицензия на программу для ЭВМ «Пачка», тип «Корпорация», модуль «Сотрудник»",
            "Лицензия на программу для ЭВМ «Пачка», тип «Корпорация», модуль «Мульти-гость»"
          ]
        },
        "months": {
          "$ref": "#/$defs/positiveInteger",
          "minimum": 3,
          "maximum": 12,
          "description": "Corporation requires 3 to 12 calendar months inclusive for every line. Ask the user to provide a term in this range; never silently increase or decrease it. Neither changes nor confirmation bypasses these limits."
        },
        "qty": {
          "$ref": "#/$defs/positiveInteger"
        },
        "price": {
          "$ref": "#/$defs/price"
        }
      },
      "required": [
        "name",
        "months",
        "qty",
        "price"
      ],
      "additionalProperties": false
    },
    "evidence": {
      "type": "object",
      "properties": {
        "document": {
          "$ref": "#/$defs/text"
        },
        "quote": {
          "$ref": "#/$defs/multiline"
        }
      },
      "required": [
        "document",
        "quote"
      ],
      "additionalProperties": false
    },
    "boundFile": {
      "type": "object",
      "properties": {
        "path": {
          "$ref": "#/$defs/text"
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      },
      "required": [
        "path",
        "sha256"
      ],
      "additionalProperties": false
    },
    "change": {
      "type": "object",
      "properties": {
        "location": {
          "$ref": "#/$defs/text"
        },
        "before": {
          "$ref": "#/$defs/multiline"
        },
        "after": {
          "$ref": "#/$defs/multiline"
        },
        "reason": {
          "$ref": "#/$defs/multiline"
        },
        "user_quote": {
          "$ref": "#/$defs/multiline"
        }
      },
      "required": [
        "location",
        "before",
        "after",
        "reason",
        "user_quote"
      ],
      "additionalProperties": false
    }
  }
}
