{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "version": "2.1.6",
    "title": "PCD Schema",
    "description": "PCD Schema für Konfigurationsdateien zur Nutzung im FLAMOX365 Artikel-Konfigurator",
    "type": "object",
    "required": [
        "format",
        "schemaVersion",
        "generatedAt",
        "product",
        "media",
        "content",
        "configuration"
    ],
    "properties": {
        "$schema": {
            "type": "string",
            "format": "uri",
            "description": "Optional: URL zur verwendeten Schema-Datei, z.B. https://www.flamox365.com/schema/pcd/2.1.6/pcd.schema.json"
        },
        "format": {
            "type": "string",
            "enum": [
                "PCD-JSON"
            ],
            "description": "Formatbezeichnung des PCD"
        },
        "schema": {
            "type": "string",
            "description": "Bezeichnung des Schemas (optional, z.B. PCD Schema)"
        },
        "schemaVersion": {
            "type": "string",
            "pattern": "^\\d+\\.\\d+\\.\\d+$",
            "description": "Schema-Version (SemVer)"
        },
        "generatedAt": {
            "type": "string",
            "format": "date",
            "description": "Datum der Erstellung der Datei (YYYY-MM-DD)"
        },
        "generatedBy": {
		    "type": "string",
		    "description": "Name der Person oder des Systems, das die Datei initial erzeugt hat"
		},
		"updatedAt": {
		    "type": "string",
		    "format": "date",
		    "description": "Datum der letzten Aktualisierung der Datei (YYYY-MM-DD)"
		},
		"updatedBy": {
		    "type": "string",
		    "description": "Name der Person oder des Systems, das die Datei zuletzt aktualisiert hat"
		},
        "notes": {
            "type": "object",
            "description": "Optional: Freie Notizen/Meta-Infos zur Datei",
            "additionalProperties": {
                "type": "string"
            }
        },
        "product": {
            "type": "object",
            "required": [
                "manufacturer",
                "internalSku",
                "model",
                "baseCurrency"
            ],
            "properties": {
                "manufacturer": {
                    "type": "string"
                },
                "internalSku": {
                    "type": "string"
                },
                "model": {
                    "type": "string"
                },
                "baseCurrency": {
                    "type": "string"
                }
            },
            "additionalProperties": false
        },
        "manufacturerContact": {
		    "type": "object",
		    "properties": {
		        "companyName": {
		            "type": "string"
		        },
		        "street": {
		            "type": "string"
		        },
		        "houseNumber": {
		            "type": "string"
		        },
		        "postalCode": {
		            "type": "string"
		        },
		        "city": {
		            "type": "string"
		        },
		        "country": {
		            "type": "string",
		            "description": "Land in englischer Sprache, z.B. Germany"
		        },
		        "email": {
		            "type": "string",
		            "format": "email"
		        },
		        "phone": {
		            "type": "string"
		        }
		    },
		    "additionalProperties": false
		},
        "energy": {
		    "type": "object",
		    "properties": {
		        "efficiencyClass": {
		            "type": "string",
		            "description": "Energieeffizienzklasse, z.B. A+"
		        },
		        "efficiencyPercent": {
		            "type": "number",
		            "description": "Wirkungsgrad in Prozent"
		        },
		        "dustMg": {
		            "type": "number",
		            "description": "Feinstaubemission in mg"
		        },
		        "coMg": {
		            "type": "number",
		            "description": "CO-Emission in mg"
		        },
		        "ecoDesign2022": {
		            "type": "boolean",
		            "description": "Kennzeichnet, ob der Artikel den EU-Ecodesign-Vorgaben entspricht"
		        }
		    },
		    "additionalProperties": false
		},
        "logistics": {
		    "type": "object",
		    "properties": {
		        "leadTimeDays": {
		            "type": "number",
		            "description": "Lieferzeit in Tagen"
		        },
		        "availability": {
		            "type": "string",
		            "enum": [
		                "inStock",
		                "madeToOrder",
		                "discontinued"
		            ],
		            "description": "Verfügbarkeitsstatus des Artikels"
		        },
		        "productionLocation": {
		            "type": "string",
		            "description": "Produktionsland in englischer Sprache, z.B. Germany"
		        }
		    },
		    "additionalProperties": false
		},
		"commerce": {
		    "type": "object",
		    "properties": {
		        "priceValidFrom": {
		            "type": "string",
		            "format": "date",
		            "description": "Startdatum der Preisgültigkeit (YYYY-MM-DD)"
		        },
		        "priceValidUntil": {
		            "type": "string",
		            "format": "date",
		            "description": "Optionales Enddatum der Preisgültigkeit (YYYY-MM-DD)"
		        }
		    },
		    "additionalProperties": false
		},
		"service": {
		    "type": "object",
		    "properties": {
		        "warrantyYears": {
		            "type": "number",
		            "description": "Garantiedauer in Jahren"
		        },
		        "sparePartsYears": {
		            "type": "number",
		            "description": "Verfügbarkeit von Ersatzteilen in Jahren"
		        }
		    },
		    "additionalProperties": false
		},
        "media": {
            "type": "object",
            "properties": {
                "images": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": [
                            "url"
                        ],
                        "properties": {
                            "url": {
                                "type": "string",
                                "format": "uri"
                            },
                            "alt": {
                                "type": "string"
                            },
                            "role": {
                                "type": "string"
                            },
                            "priority": {
                                "type": "number"
                            },
                            "match": {
                                "type": "object",
                                "additionalProperties": {
                                    "type": "string"
                                }
                            }
                        },
                        "additionalProperties": false
                    }
                },
                "documents": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": [
                            "title",
                            "url"
                        ],
                        "properties": {
                            "documenttype": {
                                "type": "string"
                            },
                            "title": {
                                "type": "string"
                            },
                            "url": {
                                "type": "string",
                                "format": "uri"
                            },
                            "role": {
                                "type": "string"
                            },
                            "category": {
                                "type": "string"
                            },
                            "priority": {
                                "type": "number"
                            },
                            "match": {
                                "type": "object",
                                "additionalProperties": {
                                    "type": "string"
                                }
                            }
                        },
                        "additionalProperties": false
                    }
                }
            },
            "additionalProperties": false
        },
        "content": {
            "type": "object",
            "properties": {
                "descriptionHtml": {
                    "type": "string"
                }
            },
            "additionalProperties": false
        },
        "configuration": {
            "type": "object",
            "required": [
                "baseSkuMatrix",
                "options"
            ],
            "properties": {
                "pricingMode": {
                    "type": "string",
                    "enum": [
                        "baseSkuMatrixPlusAddons",
                        "matrixOnly",
                        "addonsOnly"
                    ],
                    "description": "Gibt an, wie Preise berechnet werden"
                },
                "variantCoding": {
                    "type": "object",
                    "description": "Optional: Logik zur Ableitung/Formatierung von Varianten-/Artikelnummern aus Basis + Optionen",
                    "properties": {
                        "mode": {
                            "type": "string"
                        },
                        "baseFrom": {
                            "type": "string"
                        },
                        "separator": {
                            "type": "string"
                        },
                        "optionOrder": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        },
                        "valueOrder": {
                            "type": "object",
                            "description": "Wert-Reihenfolge für Coding; unterstützt legacy (flat) und neue Struktur (baseDimensions/options)",
                            "oneOf": [
                                {
                                    "type": "object",
                                    "additionalProperties": {
                                        "type": "array",
                                        "items": {
                                            "type": "string"
                                        }
                                    }
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "baseDimensions": {
                                            "type": "object",
                                            "additionalProperties": {
                                                "type": "array",
                                                "items": {
                                                    "type": "string"
                                                }
                                            }
                                        },
                                        "options": {
                                            "type": "object",
                                            "additionalProperties": {
                                                "type": "array",
                                                "items": {
                                                    "type": "string"
                                                }
                                            }
                                        }
                                    },
                                    "additionalProperties": false
                                }
                            ]
                        },
                        "output": {
                            "type": [
                                "object",
                                "string"
                            ],
                            "description": "Ausgabe-Definition; entweder string (legacy) oder Objekt",
                            "oneOf": [
                                {
                                    "type": "string"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "prefixFrom": {
                                            "type": "string"
                                        },
                                        "separator": {
                                            "type": "string"
                                        },
                                        "indexBase": {
                                            "type": "number"
                                        }
                                    },
                                    "required": [
                                        "separator"
                                    ],
                                    "additionalProperties": false
                                }
                            ]
                        },
                        "enabled": {
                            "type": "boolean"
                        },
                        "scheme": {
                            "type": "string"
                        },
                        "version": {
                            "type": "string"
                        },
                        "order": {
                            "type": "object",
                            "properties": {
                                "baseDimensions": {
                                    "type": "array",
                                    "items": {
                                        "type": "string"
                                    }
                                },
                                "options": {
                                    "type": "array",
                                    "items": {
                                        "type": "string"
                                    }
                                }
                            },
                            "additionalProperties": false
                        },
                        "compatibility": {
                            "type": "object",
                            "properties": {
                                "appendOnlyGuideline": {
                                    "type": "boolean"
                                },
                                "missingKeyBehavior": {
                                    "type": "string"
                                },
                                "unknownValueBehavior": {
                                    "type": "string"
                                }
                            },
                            "additionalProperties": false
                        },
                        "notes": {
                            "type": "string"
                        }
                    },
                    "additionalProperties": false
                },
                "baseSkuMatrix": {
                    "type": "object",
                    "required": [
                        "dimensions",
                        "items"
                    ],
                    "properties": {
                        "dimensions": {
                            "type": "array",
                            "minItems": 0,
                            "items": {
                                "type": "object",
                                "required": [
                                    "key",
                                    "label",
                                    "values"
                                ],
                                "properties": {
                                    "key": {
                                        "type": "string"
                                    },
                                    "label": {
                                        "type": "string"
                                    },
                                    "values": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "required": [
                                                "key",
                                                "label"
                                            ],
                                            "properties": {
                                                "key": {
                                                    "type": "string"
                                                },
                                                "label": {
                                                    "type": "string"
                                                }
                                            },
                                            "additionalProperties": false
                                        }
                                    },
                                    "type": {
                                        "type": "string",
                                        "description": "Dimensionstyp (z.B. enum)"
                                    }
                                },
                                "additionalProperties": false
                            }
                        },
                        "items": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "required": [
                                    "match",
                                    "label",
                                    "basePrice"
                                ],
                                "properties": {
                                    "match": {
                                        "type": "object",
                                        "description": "Mapping von dimension keys auf value keys",
                                        "additionalProperties": {
                                            "type": "string"
                                        }
                                    },
                                    "label": {
                                        "type": "string"
                                    },
                                    "basePrice": {
                                        "type": "number"
                                    },
                                    "manufacturerArticleNo": {
                                        "type": "string"
                                    }
                                },
                                "additionalProperties": false
                            }
                        }
                    },
                    "additionalProperties": false
                },
                "options": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": [
                            "key",
                            "label",
                            "values"
                        ],
                        "properties": {
                            "key": {
                                "type": "string"
                            },
                            "label": {
                                "type": "string"
                            },
                            "values": {
                                "type": "array",
                                "items": {
                                    "type": "object",
                                    "required": [
                                        "key",
                                        "label"
                                    ],
                                    "properties": {
                                        "key": {
                                            "type": "string"
                                        },
                                        "label": {
                                            "type": "string"
                                        },
                                        "priceDelta": {
                                            "type": "number"
                                        },
                                        "manufacturerArticleNo": {
                                            "type": [
                                                "string",
                                                "null"
                                            ]
                                        },
                                        "parts": {
                                            "type": "array",
                                            "items": {
                                                "type": "object",
                                                "required": [
                                                    "manufacturerArticleNo"
                                                ],
                                                "properties": {
                                                    "manufacturerArticleNo": {
                                                        "type": "string"
                                                    },
                                                    "qty": {
                                                        "type": "number"
                                                    },
                                                    "price": {
                                                        "type": "number"
                                                    }
                                                },
                                                "additionalProperties": false
                                            }
                                        }
                                    },
                                    "additionalProperties": false
                                }
                            },
                            "type": {
                                "type": "string",
                                "description": "Optionstyp (z.B. enum)"
                            }
                        },
                        "additionalProperties": false
                    }
                },
                "rules": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": [
                            "when",
                            "then"
                        ],
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "when": {
                                "type": "object",
                                "properties": {},
                                "additionalProperties": true
                            },
                            "then": {
                                "type": "object",
                                "properties": {
                                    "overridePriceDelta": {
                                        "type": "number"
                                    },
                                    "note": {
                                        "type": "string"
                                    },
                                    "requiresAny": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "option.key": {
                                                    "type": "string"
                                                },
                                                "option.valueIn": {
                                                    "type": "array",
                                                    "items": {
                                                        "type": "string"
                                                    }
                                                },
                                                "option.value": {
                                                    "type": "string"
                                                }
                                            },
                                            "additionalProperties": false
                                        }
                                    },
                                    "requiresAll": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "option.key": {
                                                    "type": "string"
                                                },
                                                "option.value": {
                                                    "type": "string"
                                                }
                                            },
                                            "additionalProperties": false
                                        }
                                    }
                                },
                                "additionalProperties": false
                            }
                        },
                        "additionalProperties": false
                    }
                }
            },
            "additionalProperties": false
        }
    },
    "additionalProperties": false
}