{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "kind": {
      "default": "other",
      "description": "Rodzaj dokumentu: 'invoice' — faktura (FV / FS / faktura zakupu), 'goodsIssuedNote' — wydanie zewnętrzne (WZ) lub dowód dostawy, 'other' — inny dokument.",
      "type": "string",
      "enum": [
        "invoice",
        "goodsIssuedNote",
        "other"
      ]
    },
    "documentDate": {
      "description": "Data wystawienia dokumentu (YYYY-MM-DD). Gdy dokument podaje kilka dat (wystawienia, sprzedaży, dostawy), zwróć datę wystawienia.",
      "type": "string"
    },
    "documentNumber": {
      "description": "Główny numer dokumentu nadany przez wystawcę (np. „WZ/0612/24/10/MG”, „FV/123/06/2026”, „WZ-34/10/25”). Na fakturze KSeF jest to numer faktury (np. „FS 1827/07/2026”), a nie numer KSeF — techniczny identyfikator postaci „6331113391-20260727-5283F2C00004-CD”, którego tu nie zwracaj.",
      "type": "string"
    },
    "buyer": {
      "default": null,
      "description": "Nazwa firmy będącej nabywcą lub odbiorcą towaru — sama nazwa podmiotu, bez osoby kontaktowej, stanowiska i adresu.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "buyerTaxId": {
      "default": null,
      "description": "NIP / Tax ID nabywcy (same cyfry).",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "supplier": {
      "default": null,
      "description": "Nazwa firmy wydającej lub sprzedającej towar — sama nazwa podmiotu, bez osoby kontaktowej i adresu.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "supplierTaxId": {
      "default": null,
      "description": "NIP / Tax ID dostawcy (same cyfry).",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "externalOrder": {
      "default": null,
      "description": "Numer zamówienia nadany przez nabywcę (odbiorcę) — numer, którym posługuje się strona zamawiająca, nie wystawca dokumentu. To inny numer niż `order`; nie zwracaj tej samej wartości w obu polach.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "order": {
      "default": null,
      "description": "Numer zamówienia lub zlecenia nadany przez wystawcę dokumentu — jego własny numer wewnętrzny. To inny numer niż `externalOrder`.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "deliveryCostNet": {
      "default": null,
      "description": "Koszt transportu / dostawy / wysyłki netto — osobna pozycja lub opłata typu „Transport”, „Usługa transportowa”, „Koszty wysyłki”, „Spedycja”. Taka pozycja NIE może równocześnie wystąpić w items. Null gdy brak.",
      "anyOf": [
        {
          "type": "number",
          "minimum": 0
        },
        {
          "type": "null"
        }
      ]
    },
    "items": {
      "default": [],
      "description": "Pozycje towarowe dokumentu — tylko wiersze tabeli pozycji, bez wierszy podsumowań. Pozycje usługowe transportu/wysyłki NIE trafiają tutaj — ich wartość netto zwróć w polu deliveryCostNet.",
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "productId": {
            "default": null,
            "description": "Kod, indeks lub symbol produktu z tabeli pozycji — krótki identyfikator, nie nazwa towaru.",
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "fullName": {
            "default": null,
            "description": "Pełna nazwa towaru / opis (wielowierszową scal w jedną).",
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "unit": {
            "default": null,
            "description": "Jednostka miary (szt / PCS / EA / SZT).",
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "quantity": {
            "default": null,
            "description": "Ilość wydana lub zafakturowana.",
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "priceNet": {
            "default": null,
            "description": "Cena jednostkowa netto pozycji (Cena netto / Cena jedn.). Zwykle na fakturach; na WZ często brak — wtedy null.",
            "anyOf": [
              {
                "type": "number",
                "minimum": 0
              },
              {
                "type": "null"
              }
            ]
          },
          "valueNet": {
            "default": null,
            "description": "Wartość netto całej pozycji (Wartość / Wartość netto). Tylko wartość wprost z dokumentu — nie wyliczaj z ceny i ilości.",
            "anyOf": [
              {
                "type": "number",
                "minimum": 0
              },
              {
                "type": "null"
              }
            ]
          },
          "vatRate": {
            "default": null,
            "description": "Stawka VAT pozycji w procentach (np. 23 dla „23%”); null gdy brak.",
            "anyOf": [
              {
                "type": "number",
                "minimum": 0
              },
              {
                "type": "null"
              }
            ]
          },
          "serialNumber": {
            "default": null,
            "description": "Numer seryjny pozycji (Nr seryjny / Serial# / „W tym:”).",
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "batchNumber": {
            "default": null,
            "description": "Numer partii (Nr partii / Partia / Batch / Lot).",
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "title": "GoodsReceivedSourceItem"
      }
    }
  },
  "title": "GoodsReceivedSource"
}
