{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vocab.groundx.ag/agro/v1/schemas/product-catalog-response.json",
  "title": "AgroProductCatalogResponse",
  "description": "Estructura de un catálogo de productos agro en JSON-LD. Sigue el patrón schema:ItemList + dcat:Dataset para combinar semántica de lista y de dataset. Cada elemento del listado es un schema:Product (subtipo agro:Agrochemical recomendado).",
  "type": "object",
  "required": ["@context", "@type", "schema:itemListElement"],
  "properties": {
    "@context": {
      "description": "JSON-LD context. Como mínimo el del perfil agro: https://vocab.groundx.ag/agro/v1/context.jsonld",
      "oneOf": [
        { "type": "string", "format": "uri" },
        { "type": "array", "items": {} }
      ]
    },
    "@id": {
      "type": "string",
      "format": "uri",
      "description": "URI canónica del catálogo (ej. la propia URL del fichero)."
    },
    "@type": {
      "description": "Tipos JSON-LD. Recomendado: ['schema:ItemList','dcat:Dataset'].",
      "oneOf": [
        { "type": "string" },
        { "type": "array", "items": { "type": "string" }, "minItems": 1 }
      ]
    },
    "dct:title":       { "type": "string", "minLength": 1 },
    "dct:description": { "type": "string" },
    "dct:publisher": {
      "type": "object",
      "required": ["@id"],
      "description": "DID del editor del catálogo.",
      "properties": {
        "@id": { "type": "string", "pattern": "^did:" }
      }
    },
    "dct:license": {
      "type": "object",
      "required": ["@id"],
      "properties": {
        "@id": { "type": "string", "format": "uri" }
      }
    },
    "dct:modified": {
      "type": "string",
      "format": "date",
      "description": "Última modificación en ISO 8601 (YYYY-MM-DD)."
    },
    "schema:numberOfItems": {
      "type": "integer",
      "minimum": 0,
      "description": "Total de productos en el catálogo. Conveniencia."
    },
    "schema:itemListElement": {
      "type": "array",
      "minItems": 0,
      "items": { "$ref": "#/$defs/product" }
    }
  },
  "additionalProperties": true,
  "$defs": {
    "product": {
      "type": "object",
      "required": ["@type", "schema:name"],
      "properties": {
        "@id": {
          "type": "string",
          "description": "URI canónica del producto. Recomendado: dereferenciable."
        },
        "@type": {
          "description": "Tipos. Recomendado: ['schema:Product','agro:Agrochemical'].",
          "oneOf": [
            { "type": "string" },
            { "type": "array", "items": { "type": "string" }, "minItems": 1 }
          ]
        },
        "schema:name":        { "type": "string", "minLength": 1 },
        "schema:description": { "type": "string" },
        "schema:manufacturer": {
          "type": "object",
          "description": "Organización fabricante. schema:Organization con al menos schema:name.",
          "properties": {
            "@type":       { "type": "string" },
            "schema:name": { "type": "string", "minLength": 1 }
          },
          "required": ["schema:name"]
        },
        "schema:brand": {
          "oneOf": [
            { "type": "string" },
            { "type": "object" }
          ]
        },
        "schema:identifier": {
          "description": "Identificadores del producto. Patrón schema:PropertyValue con propertyID/value.",
          "oneOf": [
            { "type": "string" },
            { "type": "array", "items": { "$ref": "#/$defs/propertyValue" } },
            { "$ref": "#/$defs/propertyValue" }
          ]
        },
        "agro:activeIngredient": {
          "oneOf": [
            { "type": "string" },
            { "type": "array", "items": { "type": "string" } }
          ],
          "description": "Sustancia(s) responsable(s) del efecto. ISO common name preferido."
        },
        "agro:productCategory": {
          "type": "object",
          "required": ["@id"],
          "description": "Concepto SKOS del agro:ProductCategoryScheme: Herbicide, Fungicide, Insecticide, Fertilizer, Biostimulant.",
          "properties": {
            "@id": { "type": "string" }
          }
        }
      },
      "additionalProperties": true
    },
    "propertyValue": {
      "type": "object",
      "required": ["schema:propertyID", "schema:value"],
      "properties": {
        "@type": { "type": "string", "const": "schema:PropertyValue" },
        "schema:propertyID": {
          "type": "string",
          "description": "Tipo de identificador (ej. 'ES-MAPA-fitosanitario', 'EU-PPP-registration')."
        },
        "schema:value": { "type": "string" }
      }
    }
  }
}
