{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "http://product-information-graph.org/schema/2026-01-12/jsonld/anEntity.json",
    "title": "PIG AnEntity JSON-LD Schema",
    "description": "Validates <strong>entity instances</strong> with actual property values and target link references. Includes mandatory metadata: @type (reference to Entity class), pig:revision, dcterms:modified timestamp, optional pig:priorRevision and dcterms:creator. Properties can have direct values (@value) or reference enumeration values (@id) as defined by its class. Target links reference other entity or relationship instances. Must have either dcterms:title or dcterms:description (or both) to convey meaning.",
    "type": "object",
    "properties": {
        "@id": {
            "$ref": "#/$defs/idString"
        },
        "@type": {
            "$ref": "#/$defs/idString",
            "description": "Reference to the Entity class this instance belongs to"
        },
        "pig:itemType": {
            "type": "object",
            "required": [ "@id" ],
            "properties": {
                "@id": {
                    "type": "string",
                    "enum": [ "pig:anEntity" ],
                    "description": "The PigItemType for pig:anEntity"
                }
            },
            "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 entity 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:aTargetLink" ],
                                "description": "Type of configurable item: property value or target link"
                            }
                        },
                        "additionalProperties": false
                    },
                    "@value": {
                        "type": "string",
                        "description": "Direct property value (for aProperty)"
                    },
                    "@id": {
                        "$ref": "#/$defs/idString",
                        "description": "Reference ID for enumeration value or linked entity"
                    }
                },
                "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": "aTargetLink to another entity or relationship",
                        "properties": {
                            "pig:itemType": {
                                "type": "object",
                                "properties": {
                                    "@id": {
                                        "const": "pig:aTargetLink"
                                    }
                                }
                            }
                        },
                        "required": [ "@id" ],
                        "not": {
                            "required": [ "@value" ]
                        }
                    }
                ],
                "additionalProperties": false
            }
        }
    },
    "required": [
        "@id",
        "pig:itemType",
        "@type",
        "dcterms:modified"
    ],
    "anyOf": [
        {
            "required": [ "dcterms:title" ],
            "properties": {
                "dcterms:title": {
                    "type": "array",
                    "minItems": 1
                }
            },
            "description": "Must have at least one title"
        },
        {
            "required": [ "dcterms:description" ],
            "properties": {
                "dcterms:description": {
                    "type": "array",
                    "minItems": 1
                }
            },
            "description": "Must have at least one description"
        }
    ],
    "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"
        }
    }
}