{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/akeda-ru/json-schema/akeda-ru-core-contact-schema.json",
  "title": "CoreContact",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/akeda-ru-core-contacts-api-openapi.yml#/components/schemas/CoreContact",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "name",
    "kind",
    "is_customer",
    "is_supplier",
    "folder_id",
    "entity_type",
    "legal_name",
    "phone",
    "email",
    "position",
    "tags",
    "messengers",
    "source",
    "inn",
    "kpp",
    "ogrn",
    "address",
    "legal_address",
    "postal_address",
    "bank_name",
    "bank_bic",
    "bank_account",
    "external_id",
    "custom",
    "is_active",
    "created_at",
    "updated_at",
    "payment_priority"
  ],
  "properties": {
    "id": {
      "$ref": "#/$defs/UUID"
    },
    "name": {
      "type": "string"
    },
    "kind": {
      "$ref": "#/$defs/CoreContactKind"
    },
    "is_customer": {
      "type": "boolean"
    },
    "is_supplier": {
      "type": "boolean"
    },
    "folder_id": {
      "oneOf": [
        {
          "$ref": "#/$defs/UUID"
        },
        {
          "type": "null"
        }
      ]
    },
    "entity_type": {
      "$ref": "#/$defs/CoreContactEntityType"
    },
    "legal_name": {
      "type": "string"
    },
    "phone": {
      "type": "string"
    },
    "email": {
      "type": "string"
    },
    "position": {
      "type": "string"
    },
    "tags": {
      "type": "array",
      "items": {}
    },
    "messengers": {
      "type": "object",
      "additionalProperties": true,
      "description": "Мессенджеры объектом «сеть → адрес», например {\"telegram\": \"@ivan\"} (ERP-2517). По адресам ищет параметр q списка контрагентов"
    },
    "source": {
      "type": "string"
    },
    "inn": {
      "type": "string"
    },
    "kpp": {
      "type": "string"
    },
    "ogrn": {
      "type": "string"
    },
    "address": {
      "type": "string"
    },
    "legal_address": {
      "$ref": "#/$defs/CoreContactAddress"
    },
    "postal_address": {
      "description": "Почтовый адрес для писем и печатных форм (ERP-1782). Из реестра ФНС не приходит: автозаполнение по ИНН его не меняет",
      "allOf": [
        {
          "$ref": "#/$defs/CoreContactAddress"
        }
      ]
    },
    "bank_name": {
      "type": "string"
    },
    "bank_bic": {
      "type": "string"
    },
    "bank_account": {
      "type": "string"
    },
    "external_id": {
      "type": "string"
    },
    "custom": {
      "type": "object",
      "additionalProperties": true
    },
    "is_active": {
      "type": "boolean"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    },
    "country": {
      "type": "string",
      "description": "Нерезидент: страна регистрации кодом ISO 3166 (две буквы). Пусто — Россия."
    },
    "tax_number": {
      "type": "string",
      "description": "Нерезидент: налоговый номер страны регистрации вместо ИНН."
    },
    "payment_priority": {
      "type": "string",
      "enum": [
        "high",
        "normal",
        "low"
      ],
      "description": "Приоритет оплаты по умолчанию: подставляется в новые заявки на оплату этому контрагенту, в заявке его меняют."
    },
    "title_transfer": {
      "type": "string",
      "enum": [
        "",
        "shipment",
        "acceptance"
      ],
      "description": "Переход права по умолчанию для продаж контрагенту: shipment — при отгрузке, acceptance — при приёмке покупателем (через счёт 45); пусто — по каналу продаж. Договор и продажа перекрывают (ERP-2772)"
    },
    "system_key": {
      "type": "string",
      "description": "Код системного контрагента (fns, sfr, bank:<БИК>). Только чтение."
    },
    "requisites_issue": {
      "type": "string",
      "enum": [
        "",
        "inn_missing",
        "inn_invalid",
        "kpp_invalid",
        "foreign_tax_missing",
        "country_invalid"
      ],
      "description": "Что подсветить в реквизитах по правилу ИНН. Пусто — всё в порядке."
    }
  },
  "$defs": {
    "CoreContactAddress": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "postal_code",
        "region_code",
        "region_name",
        "district",
        "city",
        "settlement",
        "street",
        "building",
        "block",
        "flat",
        "info"
      ],
      "properties": {
        "postal_code": {
          "type": "string"
        },
        "region_code": {
          "type": "string",
          "description": "Код субъекта РФ для формализованного документа"
        },
        "region_name": {
          "type": "string"
        },
        "district": {
          "type": "string"
        },
        "city": {
          "type": "string"
        },
        "settlement": {
          "type": "string"
        },
        "street": {
          "type": "string"
        },
        "building": {
          "type": "string"
        },
        "block": {
          "type": "string"
        },
        "flat": {
          "type": "string",
          "description": "Офис или помещение"
        },
        "info": {
          "type": "string"
        }
      }
    },
    "CoreContactEntityType": {
      "type": "string",
      "enum": [
        "legal",
        "individual",
        "sole_prop"
      ]
    },
    "CoreContactKind": {
      "type": "string",
      "enum": [
        "client",
        "supplier",
        "both"
      ],
      "deprecated": true,
      "description": "Legacy combined role; new clients read and patch is_customer/is_supplier independently."
    },
    "UUID": {
      "type": "string",
      "format": "uuid"
    }
  }
}