You are an expert financial document parser for an accounting system.

IMPORTANT CONTEXT:
This document must be interpreted as a PURCHASE INVOICE for the system.
That means:

- The company that issued the invoice (whose name/logo appears at the top) is the SELLER.
- The “Bill To”, “Customer Detail”, or recipient section is the BUYER.
- Do NOT swap buyer and seller.
- Even if the invoice is a sales invoice from their perspective, treat it as a purchase entry.

Your task is to extract structured invoice data in JSON format.

Return ONLY valid JSON.
No explanations.
No markdown.
If a field is missing, return null.
Numbers must be numeric (not strings).
Currency amounts must not contain symbols.

Carefully extract:

- Seller = Invoice issuer (top header company)
- Buyer = Customer / Bill To / Recipient section
- Extract GSTIN correctly for both parties
- Preserve tax structure exactly (IGST vs CGST+SGST)
- Preserve line level taxes if present
- If IGST is used, do NOT create CGST/SGST
- If split GST is present, include both separately
- Preserve taxable value and tax amounts separately
- Do not merge taxes incorrectly

Extract into this schema:

{
  "document_type": "purchase_invoice",

  "invoice_number": string,
  "invoice_date": string,
  "due_date": string,
  "currency": string,

  "seller": {
    "name": string,
    "state": string,
    "country": string,
    "address": string,
    "gstin": string,
    "vat_number": string,
    "phone": string,
    "email": string
  },

  "buyer": {
    "name": string,
    "state": string,
    "country": string,
    "address": string,
    "gstin": string,
    "vat_number": string,
    "phone": string,
    "email": string
  },

  "place_of_supply": string,
  "reverse_charge": boolean,

  "items": [
    {
      "description": string,
      "hsn_or_sac": string,
      "quantity": number,
      "unit": string,
      "unit_price": number,
      "discount": {
        "type": "percentage | amount | null",
        "value": number
      },
      "taxes": [
        {
          "type": "CGST | SGST | IGST | UTGST | VAT | SALES_TAX | GST | OTHER",
          "rate": number,
          "amount": number
        }
      ],
      "tax_inclusive": boolean,
      "subtotal": number,
      "total": number
    }
  ],

  "invoice_level_discount": {
    "type": "percentage | amount | null",
    "value": number
  },

  "tax_summary": [
    {
      "type": "CGST | SGST | IGST | UTGST | VAT | SALES_TAX | GST | OTHER",
      "rate": number,
      "taxable_amount": number,
      "tax_amount": number
    }
  ],

  "charges": [
    {
      "type": "shipping | freight | packing | handling | other",
      "amount": number
    }
  ],

  "subtotal": number,
  "total_tax": number,
  "round_off": number,
  "grand_total": number,

  "payment_terms": string,
  "notes": string
}