{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agent-gst-readiness-checker.constalabs.com/gst-invoice-readiness.schema.json",
  "title": "GST Invoice Technical Readiness Payload",
  "description": "Technical preflight schema for sanitized test data. It does not determine tax treatment or guarantee IRP acceptance.",
  "type": "object",
  "required": ["documentType", "invoiceNumber", "invoiceDate", "seller", "buyer", "items", "totals"],
  "properties": {
    "documentType": {"type": "string", "enum": ["INV", "CRN", "DBN"]},
    "invoiceNumber": {"type": "string", "minLength": 1, "maxLength": 16},
    "invoiceDate": {"type": "string", "format": "date"},
    "seller": {"$ref": "#/$defs/party"},
    "buyer": {"$ref": "#/$defs/party"},
    "items": {
      "type": "array",
      "minItems": 1,
      "items": {"$ref": "#/$defs/item"}
    },
    "totals": {
      "type": "object",
      "required": ["taxableValue", "invoiceValue"],
      "properties": {
        "taxableValue": {"$ref": "#/$defs/money"},
        "igstAmount": {"$ref": "#/$defs/money"},
        "cgstAmount": {"$ref": "#/$defs/money"},
        "sgstAmount": {"$ref": "#/$defs/money"},
        "invoiceValue": {"$ref": "#/$defs/money"}
      },
      "additionalProperties": true
    }
  },
  "$defs": {
    "money": {"type": "number", "minimum": 0},
    "party": {
      "type": "object",
      "required": ["gstin", "stateCode"],
      "properties": {
        "gstin": {"type": "string", "pattern": "^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z]$"},
        "stateCode": {"type": "string", "pattern": "^[0-9]{2}$"}
      },
      "additionalProperties": true
    },
    "item": {
      "type": "object",
      "required": ["description", "hsnSac", "quantity", "unitPrice", "taxableValue"],
      "properties": {
        "description": {"type": "string", "minLength": 1},
        "hsnSac": {"type": "string", "pattern": "^[0-9]{4,8}$"},
        "quantity": {"type": "number", "exclusiveMinimum": 0},
        "unitPrice": {"$ref": "#/$defs/money"},
        "taxableValue": {"$ref": "#/$defs/money"},
        "igstRate": {"type": "number", "minimum": 0},
        "igstAmount": {"$ref": "#/$defs/money"},
        "cgstRate": {"type": "number", "minimum": 0},
        "cgstAmount": {"$ref": "#/$defs/money"},
        "sgstRate": {"type": "number", "minimum": 0},
        "sgstAmount": {"$ref": "#/$defs/money"}
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
