{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schema.norruva.com/nrpf/v1/nrpf-v1.schema.json",
  "title": "NRPF Digital Product Passport v1",
  "description": "Norruva Regulatory Passport Format (NRPF) v1. An open, interoperable JSON Schema for structuring EU Digital Product Passport data, including fields used in ESPR, Battery Regulation (EU 2023/1542), and related EU sustainability workflows. Schema validation establishes document structure only; it does not establish legal conformity, regulatory applicability, or registry acceptance. Sub-schemas for compliance results, supply chain nodes, and evidence references are embedded in $defs for self-contained validation.",
  "$comment": "@task P2-W4-13 @epic P2-ConsumerDistribution",
  "type": "object",
  "required": [
    "id",
    "schemaVersion",
    "name",
    "category",
    "status",
    "companyId",
    "createdAt",
    "updatedAt"
  ],
  "additionalProperties": false,
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "Unique identifier for this Digital Product Passport record."
    },
    "schemaVersion": {
      "type": "string",
      "const": "nrpf-v1",
      "description": "NRPF schema version discriminator. Always 'nrpf-v1' for this schema."
    },

    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 500,
      "description": "Product name."
    },
    "productDescription": {
      "type": "string",
      "description": "Detailed product description."
    },
    "gtin": {
      "type": "string",
      "pattern": "^[0-9]{8,14}$",
      "description": "Global Trade Item Number (GTIN-8, GTIN-12, GTIN-13, or GTIN-14)."
    },
    "category": {
      "type": "string",
      "minLength": 1,
      "description": "Product category identifier (e.g. battery, textile, electronics, furniture).",
      "examples": [
        "battery",
        "textile",
        "electronics",
        "furniture",
        "construction",
        "toy",
        "food_safety"
      ]
    },
    "modelNumber": {
      "type": "string",
      "description": "Manufacturer model number."
    },
    "serialNumber": {
      "type": "string",
      "description": "Individual unit serial number (item-level granularity)."
    },
    "dateOfManufacture": {
      "type": "string",
      "format": "date",
      "description": "ISO 8601 date the product was manufactured."
    },
    "hsCode": {
      "type": "string",
      "description": "Harmonized System (HS) tariff code."
    },
    "weightKg": {
      "type": "number",
      "minimum": 0,
      "description": "Product weight in kilograms."
    },
    "weightUnit": {
      "type": "string",
      "description": "Unit for weight (defaults to 'kg').",
      "examples": ["kg", "g", "lb"]
    },
    "companyId": {
      "type": "string",
      "format": "uuid",
      "description": "Identifier of the company (manufacturer/brand) that owns this passport."
    },
    "status": {
      "type": "string",
      "enum": ["draft", "active", "archived", "suspended"],
      "description": "Lifecycle status of the passport."
    },

    "manufacturer": {
      "$ref": "#/$defs/manufacturer",
      "description": "Details of the manufacturer responsible for this product."
    },
    "manufacturing": {
      "$ref": "#/$defs/manufacturingData",
      "description": "Factory and production process details."
    },

    "compliance": {
      "$ref": "#/$defs/complianceData",
      "description": "Compliance evaluation summary for this passport."
    },
    "complianceResults": {
      "type": "array",
      "description": "Detailed per-regulation evaluation results from the compliance orchestration engine.",
      "items": { "$ref": "#/$defs/complianceResult" }
    },

    "supplyChain": {
      "$ref": "#/$defs/supplyChainData",
      "description": "Bill of Materials and supplier references."
    },

    "sustainability": {
      "$ref": "#/$defs/sustainabilityMetrics",
      "description": "Sustainability and environmental metrics."
    },
    "lifecycle": {
      "$ref": "#/$defs/lifecycleData",
      "description": "Product lifecycle information including repairability."
    },
    "endOfLife": {
      "$ref": "#/$defs/endOfLifeData",
      "description": "End-of-life handling instructions."
    },

    "evidence": {
      "type": "array",
      "description": "Evidence references (certificates, test reports, audit documents).",
      "items": { "$ref": "#/$defs/evidenceReference" }
    },

    "version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$",
      "description": "Semantic version of this passport record (e.g. '1.0.0')."
    },
    "versionNumber": {
      "type": "integer",
      "minimum": 1,
      "description": "Monotonically incrementing integer version counter."
    },
    "previousVersionId": {
      "type": ["string", "null"],
      "format": "uuid",
      "description": "Identifier of the immediately preceding passport version. Null for v1."
    },
    "amendmentReason": {
      "type": "string",
      "description": "Reason for this version update."
    },
    "isLatestVersion": {
      "type": "boolean",
      "description": "True if this is the current active version of the passport."
    },

    "urid": {
      "type": "string",
      "description": "Unique Registration Identifier assigned by the EU DPP Registry."
    },
    "registryStatus": {
      "type": "string",
      "enum": ["pending", "registered", "rejected", "suspended", "withdrawn"],
      "description": "Registration lifecycle status in the EU DPP Registry only. A value of 'registered' records a registry outcome; it is not proof of regulatory conformity or legal compliance."
    },
    "registrySubmittedAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when this passport was submitted to the EU Registry."
    },
    "registryRegisteredAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when EU Registry confirmed registration."
    },

    "applicableRegulationCodes": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Regulation codes applicable to this product (e.g. ['ESPR', 'BATTERY_REG', 'EUDR']).",
      "examples": [
        ["ESPR", "BATTERY_REG"],
        ["REACH", "ROHS", "ESPR"]
      ]
    },
    "regulationVersionSetHash": {
      "type": "string",
      "description": "Deterministic hash of the regulation version set used for evaluation. Enables deterministic replay."
    },

    "granularityType": {
      "type": "string",
      "enum": ["model", "batch", "item"],
      "description": "Granularity level of this passport: model-level, batch-level, or individual item."
    },
    "batchId": {
      "type": "string",
      "description": "Batch identifier (relevant when granularityType is 'batch')."
    },
    "batchQuantity": {
      "type": "integer",
      "minimum": 1,
      "description": "Number of units in the batch."
    },
    "parentPassportId": {
      "type": "string",
      "format": "uuid",
      "description": "Identifier of the parent (model-level) passport when granularityType is 'batch' or 'item'."
    },

    "publishedAt": {
      "type": ["string", "null"],
      "format": "date-time",
      "description": "ISO 8601 timestamp when this passport was first published."
    },
    "effectiveFrom": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 start of the validity period for this passport version."
    },
    "effectiveTo": {
      "type": ["string", "null"],
      "format": "date-time",
      "description": "ISO 8601 end of the validity period. Null means currently valid."
    },
    "evaluatedAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when the latest compliance evaluation was performed."
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when this passport was created."
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when this passport was last updated."
    },
    "createdBy": {
      "type": "string",
      "description": "User identifier of the person who created this passport."
    },
    "updatedBy": {
      "type": "string",
      "description": "User identifier of the person who last updated this passport."
    }
  },

  "$defs": {
    "manufacturer": {
      "title": "Manufacturer",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "description": "Legal name of the manufacturer."
        },
        "countryCode": {
          "type": "string",
          "pattern": "^[A-Z]{2}$",
          "description": "ISO 3166-1 alpha-2 country code of the manufacturer's registered address."
        },
        "address": {
          "type": "string",
          "description": "Street address of the manufacturer."
        },
        "eoriNumber": {
          "type": "string",
          "description": "Economic Operators Registration and Identification (EORI) number."
        },
        "contactEmail": {
          "type": "string",
          "format": "email",
          "description": "Primary contact email for product compliance enquiries."
        },
        "website": {
          "type": "string",
          "format": "uri",
          "description": "Manufacturer website URL."
        }
      }
    },

    "manufacturingData": {
      "title": "ManufacturingData",
      "description": "Factory and production data. Derived from ManufacturingData value object.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "factoryId": { "type": "string" },
        "factoryName": { "type": "string" },
        "countryCode": {
          "type": "string",
          "pattern": "^[A-Z]{2}$",
          "description": "ISO 3166-1 alpha-2 country of manufacture."
        },
        "region": { "type": "string" },
        "productionDate": {
          "type": "string",
          "format": "date",
          "description": "Date production of this unit or batch was completed."
        },
        "batchNumber": { "type": "string" },
        "lotNumber": { "type": "string" },
        "workersCount": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of workers involved in production (social compliance indicator)."
        },
        "certifications": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Factory certification identifiers (e.g. ISO9001, ISO14001)."
        }
      }
    },

    "complianceData": {
      "title": "ComplianceData",
      "description": "Overall compliance status summary. Derived from ComplianceData value object.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "overallStatus": {
          "type": "string",
          "enum": ["compliant", "non-compliant", "requires-review", "unknown"],
          "description": "Aggregated compliance status across all applicable regulations."
        },
        "passportReady": {
          "type": "boolean",
          "description": "Whether this passport meets the minimum data requirements for EU DPP publication."
        },
        "lastAssessmentDate": {
          "type": "string",
          "format": "date",
          "description": "ISO 8601 date of the most recent compliance assessment."
        },
        "targetZone": {
          "type": "string",
          "description": "Primary regulatory zone (e.g. EU, UK, US).",
          "examples": ["EU", "UK", "US"]
        },
        "certifications": {
          "type": "array",
          "description": "Product-level certifications.",
          "items": {
            "type": "object",
            "required": ["name", "issuer"],
            "additionalProperties": false,
            "properties": {
              "name": { "type": "string" },
              "issuer": { "type": "string" },
              "validUntil": { "type": "string", "format": "date" },
              "url": { "type": "string", "format": "uri" },
              "documentUrl": { "type": "string", "format": "uri" }
            }
          }
        },
        "issues": {
          "type": "array",
          "description": "Compliance issues identified.",
          "items": {
            "type": "object",
            "required": ["severity", "description"],
            "additionalProperties": false,
            "properties": {
              "severity": {
                "type": "string",
                "enum": ["low", "medium", "high", "critical"]
              },
              "description": { "type": "string" },
              "regulation": { "type": "string" }
            }
          }
        }
      }
    },

    "complianceResult": {
      "title": "ComplianceResult",
      "description": "Per-regulation evaluation result from the compliance orchestration engine. Derived from RegulationResult interface in OrchestrationResult.",
      "type": "object",
      "required": ["regulation", "status", "reason"],
      "additionalProperties": false,
      "properties": {
        "regulation": {
          "type": "string",
          "description": "Regulation code (e.g. BATTERY_REG, ESPR, EUDR, REACH, ROHS)."
        },
        "status": {
          "type": "string",
          "enum": ["passed", "failed", "warning", "not_applicable", "pending"]
        },
        "reason": {
          "type": "string",
          "description": "Human-readable explanation of the evaluation outcome."
        },
        "score": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Numeric compliance score for this regulation (0–100)."
        },
        "violations": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["ruleId", "severity", "description"],
            "additionalProperties": false,
            "properties": {
              "ruleId": { "type": "string" },
              "severity": {
                "type": "string",
                "enum": ["low", "medium", "high", "critical"]
              },
              "description": { "type": "string" },
              "field": { "type": "string" },
              "remediation": { "type": "string" }
            }
          }
        },
        "details": {
          "type": "object",
          "additionalProperties": true
        },
        "evaluatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },

    "supplyChainData": {
      "title": "SupplyChainData",
      "description": "Bill of Materials and supply chain structure.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "bomNodes": {
          "type": "array",
          "description": "Flat list of BOM nodes representing the full component hierarchy.",
          "items": { "$ref": "#/$defs/supplyChainNode" }
        },
        "supplierCount": {
          "type": "integer",
          "minimum": 0,
          "description": "Total number of distinct suppliers in this supply chain."
        },
        "countryCount": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of distinct countries of origin across all BOM nodes."
        }
      }
    },

    "supplyChainNode": {
      "title": "SupplyChainNode",
      "description": "A single BOM node (product, assembly, component, raw material, or packaging). Derived from BOMNodeProps.",
      "type": "object",
      "required": [
        "id",
        "name",
        "nodeType",
        "quantity",
        "unitOfMeasure",
        "level"
      ],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "parentId": { "type": ["string", "null"], "format": "uuid" },
        "name": { "type": "string", "minLength": 1, "maxLength": 255 },
        "partNumber": { "type": "string" },
        "description": { "type": "string" },
        "nodeType": {
          "type": "string",
          "enum": [
            "PRODUCT",
            "ASSEMBLY",
            "COMPONENT",
            "RAW_MATERIAL",
            "PACKAGING"
          ]
        },
        "quantity": { "type": "number", "exclusiveMinimum": 0 },
        "unitOfMeasure": { "type": "string" },
        "unitCost": { "type": "number", "minimum": 0 },
        "currency": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "materials": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "materialName",
              "materialClass",
              "weightKg",
              "weightPercent"
            ],
            "additionalProperties": false,
            "properties": {
              "materialName": { "type": "string" },
              "materialClass": { "type": "string" },
              "weightKg": { "type": "number", "minimum": 0 },
              "weightPercent": {
                "type": "number",
                "minimum": 0,
                "maximum": 100
              },
              "recycledContentPercent": {
                "type": "number",
                "minimum": 0,
                "maximum": 100
              },
              "hazardClass": { "type": "string" },
              "certifications": {
                "type": "array",
                "items": { "type": "string" }
              }
            }
          }
        },
        "totalWeightKg": { "type": "number", "minimum": 0 },
        "recycledContentPercent": {
          "type": "number",
          "minimum": 0,
          "maximum": 100
        },
        "supplierId": { "type": "string" },
        "supplierPartNumber": { "type": "string" },
        "leadTimeDays": { "type": "integer", "minimum": 0 },
        "carbonFootprintKg": { "type": "number", "minimum": 0 },
        "countryOfOrigin": { "type": "string", "pattern": "^[A-Z]{2}$" },
        "level": { "type": "integer", "minimum": 0 },
        "sortOrder": { "type": "integer", "minimum": 0 },
        "childCount": { "type": "integer", "minimum": 0 }
      }
    },

    "sustainabilityMetrics": {
      "title": "SustainabilityMetrics",
      "description": "Product sustainability and environmental performance metrics. Derived from SustainabilityData value object (@modules/compliance-kernel/domain/value-objects/SustainabilityData.ts).",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "carbonFootprintKgCO2": {
          "type": "number",
          "minimum": 0,
          "description": "Product carbon footprint in kg CO2-equivalent (cradle-to-grave, per unit)."
        },
        "recyclabilityPercentage": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Percentage of the product (by weight) that is recyclable at end of life."
        },
        "recycledContentPercentage": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Percentage of the product (by weight) made from recycled input materials."
        },
        "sustainabilityScore": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Composite sustainability score (0–100) calculated by the Norruva scoring engine."
        },
        "circularityScore": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Circularity score measuring end-of-life reuse, repair, and recycling potential (0–100)."
        },
        "recommendations": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Actionable recommendations to improve sustainability performance."
        }
      }
    },

    "lifecycleData": {
      "title": "LifecycleData",
      "description": "Product lifecycle information. Derived from LifecycleData value object.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "expectedLifetime": {
          "type": "object",
          "additionalProperties": false,
          "required": ["value", "unit"],
          "properties": {
            "value": { "type": "number", "minimum": 0 },
            "unit": {
              "type": "string",
              "enum": ["years", "months", "days", "cycles", "km"],
              "description": "Unit for expected lifetime."
            }
          }
        },
        "energyEfficiencyClass": {
          "type": "string",
          "description": "EU energy efficiency class (e.g. A, A+, B, C).",
          "examples": ["A", "A+", "A++", "B", "C", "D", "E", "F", "G"]
        },
        "annualEnergyConsumptionKWh": {
          "type": "number",
          "minimum": 0,
          "description": "Rated annual energy consumption in kilowatt-hours."
        },
        "repairabilityIndex": {
          "$ref": "#/$defs/repairabilityProfile"
        },
        "maintenance": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Maintenance instructions or requirements."
        }
      }
    },

    "repairabilityProfile": {
      "title": "RepairabilityProfile",
      "description": "EU repairability index score and breakdown. Derived from RepairabilityProfile value object.",
      "type": "object",
      "required": ["score", "class"],
      "additionalProperties": false,
      "properties": {
        "score": {
          "type": "number",
          "minimum": 0,
          "maximum": 10,
          "description": "Overall repairability score (0.0–10.0, higher is more repairable)."
        },
        "class": {
          "type": "string",
          "enum": ["A", "B", "C", "D", "E"],
          "description": "EU repairability class (A = most repairable, E = least repairable)."
        },
        "breakdown": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "documentation",
            "disassembly",
            "spareParts",
            "software"
          ],
          "properties": {
            "documentation": {
              "type": "number",
              "minimum": 0,
              "maximum": 10,
              "description": "Score for availability of repair documentation."
            },
            "disassembly": {
              "type": "number",
              "minimum": 0,
              "maximum": 10,
              "description": "Score for ease of disassembly."
            },
            "spareParts": {
              "type": "number",
              "minimum": 0,
              "maximum": 10,
              "description": "Score for availability and pricing of spare parts."
            },
            "software": {
              "type": "number",
              "minimum": 0,
              "maximum": 10,
              "description": "Score for software update and reset capability."
            }
          }
        }
      }
    },

    "endOfLifeData": {
      "title": "EndOfLifeData",
      "description": "End-of-life handling instructions. Derived from EndOfLifeData value object.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "recyclingInstructions": {
          "type": "string",
          "description": "Instructions for recycling this product at end of life."
        },
        "hazards": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Hazardous materials or substances requiring special disposal handling."
        },
        "disposalChannels": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Recommended disposal or collection channels (e.g. WEEE point, municipal hazardous waste)."
        },
        "recyclabilityPercentage": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Percentage of the product (by weight) that can be recycled."
        }
      }
    },

    "evidenceReference": {
      "title": "EvidenceReference",
      "description": "Reference to a compliance evidence artefact. Derived from Evidence entity (@modules/compliance-evidence/domain/entities/Evidence.ts).",
      "type": "object",
      "required": [
        "id",
        "category",
        "fileName",
        "validationStatus",
        "uploadedBy",
        "createdAt"
      ],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "passportId": { "type": "string", "format": "uuid" },
        "category": {
          "type": "string",
          "enum": ["certificate", "manual", "test_report", "image"]
        },
        "fileName": { "type": "string", "minLength": 1 },
        "fileSize": { "type": "integer", "minimum": 0 },
        "mimeType": { "type": "string" },
        "publicUrl": { "type": "string", "format": "uri" },
        "validationStatus": {
          "type": "string",
          "enum": ["pending", "verified", "rejected"]
        },
        "failureReason": { "type": "string" },
        "uploadedBy": { "type": "string" },
        "contentHash": {
          "type": ["string", "null"],
          "pattern": "^[0-9a-f]{64}$",
          "description": "SHA-256 hex digest for tamper detection."
        },
        "hashAlgorithm": { "type": ["string", "null"] },
        "createdAt": { "type": "string", "format": "date-time" },
        "updatedAt": { "type": "string", "format": "date-time" }
      }
    }
  }
}
