{
  "type": "object",
  "properties": {
    "timestamp": {
      "type": "string"
    },
    "source_id": {
      "type": "number",
      "minimum": 0,
      "maximum": 9,
      "multipleOf": 1
    },
    "external_id": {
      "type": "string",
      "maxLength": 128
    },
    "service": {
      "type": "object",
      "properties": {
        "callback_url": {
          "type": "string",
          "maxLength": 256
        }
      }
    },
    "correction": {
      "type": "object",
      "properties": {
        "company": {
          "type": "object",
          "properties": {
            "sno": {
              "enum": [
                "osn",
                "usn_income",
                "usn_income_outcome",
                "envd",
                "esn",
                "patent"
              ]
            },
            "inn": {
              "type": "string",
              "maxLength": 12
            },
            "payment_address": {
              "type": "string",
              "maxLength": 256
            },
            "location": {
              "type": "string",
              "maxLength": 256
            }
          },
          "required": [
            "inn",
            "payment_address"
          ]
        },
        "client": {
          "type": "object",
          "properties": {
            "email": {
              "anyOf": [
                { "type": "null" },
                {
                  "type": "string",
                  "maxLength": 64,
                  "pattern": "^.+@.+$"
                }
              ]
            },
            "phone": {
              "anyOf": [
                { "type": "null" },
                {
                  "type": "string",
                  "maxLength": 19,
                  "pattern": "^\\+\\d+$"
                }
              ]
            }
          }
        },
        "cashier": {
          "type": "string",
          "maxLength": 64
        },
        "correction_info": {
          "type": "object",
          "properties": {
            "type": {
              "enum": [
                "self",
                "instruction"
              ]
            },
            "base_date": {
              "type": "string"
            },
            "base_number": {
              "type": "string"
            }
          },
          "allOf": [
            {
              "required": [
                "type",
                "base_date"
              ]
            },
            {
              "anyOf": [
                {
                  "properties": {
                    "type": {
                      "enum": [
                        "self"
                      ]
                    }
                  }
                },
                {
                  "properties": {
                    "type": {
                      "enum": [
                        "instruction"
                      ]
                    }
                  },
                  "required": [
                    "base_number"
                  ]
                }
              ]
            }
          ]
        },
        "payments": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10,
          "items": {
            "type": "object",
            "properties": {
              "type": {
                "$ref": "#/definitions/type_format"
              },
              "sum": {
                "$ref": "#/definitions/sum_number_two_format"
              }
            },
            "required": [
              "type",
              "sum"
            ]
          }
        },
        "vats": {
          "type": "array",
          "minItems": 1,
          "maxItems": 6,
          "items": {
            "type": "object",
            "properties": {
              "type": {
                "enum": [
                  "none",
                  "vat0",
                  "vat10",
                  "vat18",
                  "vat110",
                  "vat118",
                  "vat20",
                  "vat120",
                  "vat5",
                  "vat7",
                  "vat105",
                  "vat107",
                  "vat22",
                  "vat122"
                ]
              },
              "sum": {
                "$ref": "#/definitions/sum_number_two_format"
              }
            },
            "required": [
              "type",
              "sum"
            ]
          }
        },
        "device_number": {
          "type": "string",
          "maxLength": 20
        },
        "internet": {
          "type": "boolean"
        }
      },
      "required": [
        "company",
        "payments",
        "vats",
        "correction_info"
      ],
      "allOf": [
        {
          "anyOf": [
            {
              "anyOf": [
                {
                  "not": {
                    "required": [
                      "internet"
                    ]
                  }
                },
                {
                  "required": [
                    "internet"
                  ],
                  "properties": {
                    "internet": {
                      "enum": [false]
                    }
                  }
                }
              ]
            },
            {
              "allOf": [
                {
                  "required": [
                    "internet"
                  ],
                  "properties": {
                    "internet": {
                      "enum": [ true ]
                    }
                  }
                },
                {
                  "required": [
                    "client"
                  ]
                },
                {
                  "properties": {
                    "client": {
                      "type": "object",
                      "anyOf": [
                        {
                          "required": [
                            "email"
                          ]
                        },
                        {
                          "required": [
                            "phone"
                          ]
                        }
                      ]
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  },
  "definitions": {
    "sum_number_two_format": {
      "anyOf": [
        {
          "type": "number",
          "minimum": 0,
          "maximum": 10000000000,
          "multipleOf": 0.01
        },
        {
          "type": "null"
        }
      ]
    },
    "type_format": {
      "type": "integer",
      "enum": [
        0,
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9
      ]
    }
  },
  "required": [
    "timestamp",
    "external_id",
    "correction"
  ]
}