{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "_common.schema.json",
    "description": "Общие объекты",
    "status": {
        "enum": ["ACTIVE", "INACTIVE", "INVITED"],
        "description": "Статус  \n\n - `ACTIVE`: активный \n - `INACTIVE`: заблокированный \n - `INVITED`: Отправлено приглашение"
    },
    "userRole": {
        "enum": [
            "ADMINISTRATOR",
            "CONTRACTOR",
            "CUSTOMER",
            "OBSERVER",
            "PARTNER",
            "COMPLIANCE",
            "SENIOR_COMPLIANCE"
        ],
        "description": "Роль пользователя"
    },
    "country": {
        "type": "string",
        "minLength": 3,
        "maxLength": 3,
        "pattern": "^[A-Z]{3}$",
        "description": "Код страны в ISO A3 (RUS, ARM, ...)"
    },
    "currency": {
        "type": "string",
        "minLength": 3,
        "maxLength": 3,
        "pattern": "^[A-Z]{3}$",
        "description": "Код валюты"
    },
    "address": {
        "description": "Адрес",
        "properties":{
            "address": {
                "type": "string",
                "description": "Адрес"
            },
            "zipCode": {
                "type": "string",
                "description": "Почтовый индекс"
            },
            "additionalProperties": false,
            "required": [
                "address"
            ]
        }
    },
    "bankAccount": {
        "type": "array",
        "minItems": 0,
        "description": "Реквизиты банковского счета",
        "items": {
            "type": "object",
            "properties": {
                "isPriority": {
                    "type": "boolean",
                    "description": "Признак приоритетного счета в указанной валюте"
                },
                "number": {
                    "type": "string",
                    "maxLength": 50,
                    "pattern": "^[0-9a-zA-Z]+$",
                    "description": "Номер счета"
                },
                "bank": {
                    "#ref": "bank.schema.json",
                    "description": "Банк РФ"
                },
                "foreignBank": {
                    "#ref": "swift.schema.json",
                    "description": "Банк из списка SWIFT"
                },
                "bankAccountType":{
                    "enum": [
                            "RUS",
                            "FOREIGN"
                        ]
                },
                "currency":{
                    "#ref": "#/currency"
                },
                "status": {
                    "enum": ["ACTIVE", "INACTIVE"],
                    "description": "Статус  \n\n - `ACTIVE`: активный \n - `INACTIVE`: заблокированный"
                }
            },
            "additionalProperties": false,
            "required": [
                "number"
            ]
        }
    },
    "fio": {
        "description": "ФИО",
        "properties": {
            "lastName": {
                "type": "string",
                "description": "Фамилия"
            },
            "firstName": {
                "type": "string",
                "description": "Имя"
            },
            "patronymic": {
                "type": "string",
                "description": "Отчество"
            }
        },
        "additionalProperties": false,
        "required": [
            "lastName",
            "firstName"
        ]
    },
    "email": {
        "type": "string",
        "description": "Адрес электронной почты",
        "pattern": "(?=^[\\w\\W]{0,255}$)^\\s*(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])\\s*$"
    },
    "titleDetails": {
        "type": "object",
        "description": "Должность",
        "properties": {
            "name" : {
                "type" : "string",
                "description" : "Наименование"
            },
            "genitiveCase" : {
                "type" : "string",
                "description" : "Наименование в родительном падеже"
            },
            "englishName" : {
                "type" : "string",
                "description" : "Наименование на английском языке"
            }
        },
        "required": [
            "name",
            "genitiveCase",
            "englishName"
        ]
    },
    "representative": {
        "type": "object",
        "description": "Подписант",
        "properties": {
            "fio": {
                "$ref": "#/fio"
            },
            "fioGenitiveCase": {
                "$ref": "#/fio",
                "description": "ФИО в родительном падеже"
            },
            "fioEnglish": {
                "$ref": "#/fio",
                "description": "ФИО на английском языке"
            },
            "title": {
                "description": "Должность",
                "titleId": {
                    "$ref": "../title.schema.json",
                    "description": "Должность из справочника"
                },
                "titleDetails" : {
                    "$ref": "#/titleDetails",
                    "description" : "Должность"
                }
            },
            "signPath" : {
                    "type": "string",
                    "description" : "Путь к файлу с изображением подписи"
                },
            "actionBasis": {
                "type": "object",
                "description": "Основание полномочий подписанта",
                "properties": {
                    "type": {
                        "enum": [
                            "CHARTER",
                            "POA",
                            "OTHER"
                        ],
                        "description": "Тип оснований \n\n - `CHARTER`: Устав \n - `POA`: Доверенность \n - `OTHER`: Другое\""
                    },
                    "number": {
                        "type": "string",
                        "description": "Номер документа"
                    },
                    "notValidAfter": {
                        "type": "string",
                        "format": "date",
                        "description": "Срок окончания действия документа полномочий"
                    },
                    "name": {
                        "type": "string",
                        "description": "Название документа для типа 'Другое'"
                    },
                    "nameEnglish": {
                        "type": "string",
                        "description": "Название документа на английском для типа 'Другое'"
                    }
                },
                "additionalProperties": false,
                "required": [
                    "type"
                ]
            }
        },
        "additionalProperties": false,
        "required": [
            "fio",
            "title",
            "actionBasis"
        ]
    }
}
