{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": [
    "typ",
    "symbol_magazynu",
    "symbol_kontrahenta",
    "data_wystawienia",
    "pozycje"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "typ": { "const": "FZ" }
        }
      },
      "then": {
        "required": [ "numer_fv", "waluta" ]
      }
    }
  ],
  "properties": {
    "typ": {
      "type": "string",
      "enum": [
        "FZ",
        "PZ",
        "WZ"
      ]
    },
    "symbol_magazynu": {
      "type": "string"
    },
    "symbol_kontrahenta": {
      "type": "string"
    },
    "numer_fv": {
      "type": "string"
    },
    "data_wystawienia": {
      "type": "string",
      "format": "date"
    },
    "data_magazynowa": {
      "type": "string",
      "format": "date"
    },
    "data_sprzedazy": {
      "type": "string",
      "format": "date"
    },
    "data_otrzymania": {
      "type": "string",
      "format": "date"
    },
    "sposob_rozliczenia": {
      "type": "string",
      "enum": [
        "netto",
        "brutto"
      ]
    },
    "rodzaj_transakcji_vat": {
      "type": "integer",
      "enum": [
        0,
        1,
        2,
        3,
        4,
        6,
        12,
        21,
        22,
        23
      ]
    },
    "waluta": {
      "type": "string"
    },
    "wartosc": {
      "type": "number"
    },
    "skutek_magazynowy": {
      "type": "integer",
      "enum": [
        0,
        1,
        3
      ]
    },
    "pozycje": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "ilosc",
          "cena",
          "symbol_stawki_vat"
        ],
        "anyOf": [
          {
            "required": [
              "sku"
            ]
          },
          {
            "required": [
              "ean"
            ]
          }
        ],
        "properties": {
          "nazwa": {
            "type": "string"
          },
          "sku": {
            "type": "string"
          },
          "ean": {
            "type": "string"
          },
          "ilosc": {
            "type": "number"
          },
          "cena": {
            "type": "number"
          },
          "stawka_vat": {
            "type": "number"
          },
          "symbol_stawki_vat": {
            "type": "string"
          },
          "jednostka": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    }
  },
  "additionalProperties": true
}