{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "http://product-information-graph.org/schema/2026-01-12/jsonld/aRelationship.json",
    "title": "PIG ARelationship JSON-LD Schema",
    "description": "Validates <strong>relationship instances</strong> representing directed, reified connections between items (i.e. entity or relationship instances). Similar metadata to entities, but additionally requires both source links (pig:aSourceLink) and target links (pig:aTargetLink) conforming to the class definition. Source and target links reference entity or relationship instances. Properties can carry contextual information about the relationship (e.g., traceability status, rationale, coverage analysis). Reification enables relationships to be first-class items with their own lifecycle and properties. Must have a dcterms:title and optionally a dcterms:description to convey meaning.",
    "type": "object",
    "properties": {
        "@id": {
            "$ref": "#/$defs/idString"
        },
        "@type": {
            "$ref": "#/$defs/idString",
            "description": "Reference to the Relationship class this instance belongs to"
        },
        "pig:itemType": {
            "type": "object",
            "required": [ "@id" ],
            "properties": {
                "@id": {
                    "type": "string",
                    "enum": [ "pig:aRelationship" ],
                    "description": "The PigItemType for pig:aRelationship"
                }
            },
            "additionalProperties": false
        },
        "pig:revision": {
            "type": "string",
            "description": "Revision identifier for version control"
        },
        "pig:priorRevision": {
            "type": "array",
            "description": "Array of prior revision identifiers",
            "items": {
                "type": "string"
            }
        },
        "dcterms:modified": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp of last modification"
        },
        "dcterms:creator": {
            "type": "string",
            "description": "Creator/author of this relationship instance"
        },
        "dcterms:title": {
            "type": "array",
            "description": "Multi-language titles",
            "items": {
                "$ref": "#/$defs/languageValue"
            }
        },
        "dcterms:description": {
            "type": "array",
            "description": "Multi-language descriptions",
            "items": {
                "$ref": "#/$defs/languageValue"
            }
        }
    },
    "patternProperties": {
        "^(?!pig:itemType|pig:revision|pig:priorRevision|@id|@type|dcterms:modified|dcterms:creator|dcterms:title|dcterms:description)([A-Za-z0-9_\\-]+:[^:\\s]+|https?:\\/\\/[^\\s]+)$": {
            "type": "array",
            "description": "Configurable properties and links with namespaced keys",
            "items": {
                "type": "object",
                "properties": {
                    "pig:itemType": {
                        "type": "object",
                        "required": [ "@id" ],
                        "properties": {
                            "@id": {
                                "type": "string",
                                "enum": [ "pig:aProperty", "pig:aSourceLink", "pig:aTargetLink" ],
                                "description": "Type of configurable item: property value, source link, or target link"
                            }
                        },
                        "additionalProperties": false
                    },
                    "@value": {
                        "type": "string",
                        "description": "Direct property value (for aProperty)"
                    },
                    "@id": {
                        "$ref": "#/$defs/idString",
                        "description": "Reference to enumeration value or linked entity/relationship"
                    }
                },
                "required": [ "pig:itemType" ],
                "oneOf": [
                    {
                        "type": "object",
                        "description": "aProperty with direct value",
                        "properties": {
                            "pig:itemType": {
                                "type": "object",
                                "properties": {
                                    "@id": {
                                        "const": "pig:aProperty"
                                    }
                                }
                            }
                        },
                        "required": [ "@value" ],
                        "not": {
                            "required": [ "@id" ]
                        }
                    },
                    {
                        "type": "object",
                        "description": "aProperty with enumeration reference",
                        "properties": {
                            "pig:itemType": {
                                "type": "object",
                                "properties": {
                                    "@id": {
                                        "const": "pig:aProperty"
                                    }
                                }
                            }
                        },
                        "required": [ "@id" ],
                        "not": {
                            "required": [ "@value" ]
                        }
                    },
                    {
                        "type": "object",
                        "description": "aSourceLink or aTargetLink to another entity or relationship",
                        "properties": {
                            "pig:itemType": {
                                "type": "object",
                                "properties": {
                                    "@id": {
                                        "enum": [ "pig:aSourceLink", "pig:aTargetLink" ]
                                    }
                                }
                            }
                        },
                        "required": [ "@id" ],
                        "not": {
                            "required": [ "@value" ]
                        }
                    }
                ],
                "additionalProperties": false
            }
        }
    },
    "required": [
        "@id",
        "pig:itemType",
        "@type",
        "dcterms:modified"
    ],
    "additionalProperties": false,
    "$defs": {
        "idString": {
            "type": "string",
            "pattern": "^(?:[A-Za-z0-9_\\-]+:[^:\\s]+|https?:\\/\\/[^\\s]+)$",
            "description": "A valid ID string: either a namespaced identifier (prefix:name) or a URL"
        },
        "languageValue": {
            "type": "object",
            "required": [ "@value" ],
            "properties": {
                "@value": {
                    "type": "string",
                    "description": "The actual text content"
                },
                "@language": {
                    "type": "string",
                    "pattern": "^[a-z]{2}(-[A-Z]{2})?$",
                    "description": "IETF language tag (e.g., 'en', 'de', 'en-US')"
                }
            },
            "additionalProperties": false,
            "description": "Multi-language text value with optional language tag"
        }
    }
}
