{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "title": "EUDR RegulatoryNotification JSON Schema",
    "description": "JSON schema for validating the GS1 EUDR RegulatoryNotification message. Mandatory properties are type, messageSender, messageRecipient and regulatoryInformation.",
    "$defs": {
        "regulatoryAct": {
            "description": "For these messages, the value of the regulatoryAct property must always be exactly 'EU 2023/1115'",
            "type": "string",
            "enum": [
                "EU 2023/1115"
            ],
            "default": "EU 2023/1115"
        },
        "regulationType": {
            "description": "For these messages, the value of the regulationType property must always be exactly 'DEFORESTATION_REGULATION'",
            "type": "string",
            "enum": [
                "DEFORESTATION_REGULATION"
            ],
            "default": "DEFORESTATION_REGULATION"
        },
        "regulatoryIdentifierType": {
            "description": "For these messages, the value of the regulatoryIdentifierType property must always be exactly 'DUE_DILIGENCE_STATEMENT'",
            "type": "string",
            "enum": [
                "DUE_DILIGENCE_STATEMENT"
            ],
            "default": "DUE_DILIGENCE_STATEMENT"
        },
        "ProductIdentifier": {
            "description": "The definition for ProductIdentifier matches either a GS1 Digital Link URI that specifies at least a GTIN using /01/ followed by 14 digits - or an object that specifies at least the gs1:gtin property with a 14-digit numeric string value",
            "oneOf": [
                {
                    "description": "When a product identifier is specified as an object, the gtin property is mandatory.",
                    "type": "object",
                    "properties": {
                        "gtin": {
                            "description": "Match against a 14-digit numeric string",
                            "type": "string",
                            "pattern": "\\d{14}"
                        },
                        "hasBatchLotNumber": {
                            "description": "If specified, match the value for the batch/lot ID against an alphanumeric string up to 20 characters, each from within the GS1 AI encodable character set 82",
                            "type": "string",
                            "pattern": "^([!%-?A-Z_a-z\\x22]{1,20})$"
                        },
                        "hasSerialNumber": {
                            "description": "If specified, match the value for the serial number against an alphanumeric string up to 20 characters, each from within the GS1 AI encodable character set 82",
                            "type": "string",
                            "pattern": "^([!%-?A-Z_a-z\\x22]{1,20})$"
                        }
                    },
                    "if": {
                        "description": "If batchLotNumber or serialNumber are specified, gtin must also be specified",
                        "anyOf": [
                            {
                                "required": [
                                    "hasBatchLotNumber"
                                ]
                            },
                            {
                                "required": [
                                    "hasSerialNumber"
                                ]
                            }
                        ]
                    },
                    "then": {
                        "required": [
                            "gtin"
                        ]
                    },
                    "required": [
                        "gtin"
                    ]
                },
                {
                    "description": "If the value is a GS1 Digital Link URI, check for a match against /01/ followed by 14 digits",
                    "type": "string",
                    "format": "uri",
                    "pattern": "/01/\\d{14}"
                }
            ]
        },
        "OrganizationIdentifier": {
            "description": "The definition for OrganizationIdentifier matches either a GS1 Digital Link URI that specifies at least a Party GLN using /417/ followed by 13 digits - or an object that specifies the gs1:partyGLN property with a 13-digit numeric string value",
            "oneOf": [
                {
                    "description": "When expressed as an object, the partyGLN property is mandatory and its value must be a 13-digit numeric string.",
                    "type": "object",
                    "properties": {
                        "partyGLN": {
                            "description": "Match against 13-digit numeric string",
                            "type": "string",
                            "pattern": "\\d{13}"
                        }
                    },
                    "required": [
                        "partyGLN"
                    ]
                },
                {
                    "description": "If the value is a GS1 Digital Link URI, check for a match against /417/ followed by 13 digits",
                    "type": "string",
                    "format": "uri",
                    "pattern": "/417/\\d{13}"
                }
            ]
        },
        "RegulatoryIdentifierObject": {
            "description": "The definition for the RegulatoryIdentifierObject attempts to validate the RegulatoryIdentifier class. Mandatory properties are referenceNumber, verificationNumber, applicableProducts and regulatoryIdentifierType.",
            "type": "object",
            "properties": {
                "regulatoryReferenceNumber": {
                    "description": "The value for the referenceNumber property must be a string",
                    "type": "string"
                },
                "regulatoryVerificationNumber": {
                    "description": "The value for the verificationNumber property must be a string",
                    "type": "string"
                },
                "regulatoryInformationProvider": {
                    "description": "The value of regulatoryInformationProvider should be expressed as an object that specifies the gs1:partyGLN property - or as a corresponding GS1 Digital Link URI that includes the pattern /417/ followed by a 13 digit GLN value",
                    "$ref": "#/$defs/OrganizationIdentifier"
                },
                "regulatoryReferenceApplicabilityStartDate": {
                    "description": "Match against a valid xsd:date string formatted as YYYY-MM-DD where MM is in the range 01-12 and DD is in the range 01-31",
                    "type": "string",
                    "format": "date"
                },
                "regulatoryReferenceApplicabilityEndDate": {
                    "description": "Match against a valid xsd:date string formatted as YYYY-MM-DD where MM is in the range 01-12 and DD is in the range 01-31",
                    "type": "string",
                    "format": "date"
                },
                "regulatoryIdentifierType": {
                    "description": "Match against the validation definition for the RegulatoryIdentifier class and its properties",
                    "$ref": "#/$defs/regulatoryIdentifierType"
                },
                "applicableProducts": {
                    "description": "The value for the applicableProducts property may be a single object validating against the ProductIdentifier definition - or a list array of such objects",
                    "oneOf": [
                        {
                            "type": "array",
                            "items": {
                                "$ref": "#/$defs/ProductIdentifier"
                            }
                        },
                        {
                            "type": "object",
                            "$ref": "#/$defs/ProductIdentifier"
                        }
                    ]
                }
            },
            "required": [
                "regulatoryReferenceNumber",
                "regulatoryVerificationNumber",
                "applicableProducts",
                "regulatoryIdentifierType"
            ]
        },
        "RegulatoryInformationObject": {
            "description": "The definition for the RegulatoryInformationObject attempts to validate the RegulatoryInformation class. Mandatory properties are regulatoryAct, regulationType and regulatoryIdentifier.",
            "type": "object",
            "properties": {
                "regulatoryAct": {
                    "description": "The value of the regulatoryAct property must match the expected value.",
                    "$ref": "#/$defs/regulatoryAct"
                },
                "regulationType": {
                    "description": "The value of the regulationType property must match the expected value.",
                    "$ref": "#/$defs/regulationType"
                },
                "applicableTransactions": {
                    "description": "The value of the applicableTransactions property may be an object that specifies a transactionID and transactionType - or a list array of such objects",
                    "oneOf": [
                        {
                            "type": "array",
                            "items": {
                                "$ref": "#/$defs/TransactionObject"
                            }
                        },
                        {
                            "type": "object",
                            "$ref": "#/$defs/TransactionObject"
                        }
                    ]
                },
                "regulatoryIdentifier": {
                    "description": "The value of the regulatoryIdentifier property may be an object that matches the definition for RegulatoryIdentifierObject - or a list array of such objects",
                    "oneOf": [
                        {
                            "type": "array",
                            "items": {
                                "$ref": "#/$defs/RegulatoryIdentifierObject"
                            }
                        },
                        {
                            "type": "object",
                            "$ref": "#/$defs/RegulatoryIdentifierObject"
                        }
                    ]
                }
            },
            "required": [
                "regulatoryAct",
                "regulationType",
                "regulatoryIdentifier"
            ]
        },
        "TransactionObject": {
            "description": "The definition for the TransactionObject expects an object in which string values are specified for both the transactionType property and for the transactionID property",
            "type": "object",
            "properties": {
                "transactionType": {
                    "type": "string"
                },
                "transactionDate": {
                    "description": "Match against a valid xsd:date string formatted as YYYY-MM-DD where MM is in the range 01-12 and DD is in the range 01-31",
                    "type": "string",
                    "format": "date"
                },
                "transactionID": {
                    "type": "string"
                }
            },
            "required": [
                "transactionType",
                "transactionID"
            ]
        }
    },
    "type": "object",
    "properties": {
        "@context": {
            "description": "the value of the @context property should be a JSON-LD context resource for this EUDR RegulatoryNotification message, specified by a URL and provided by GS1.",
            "type": "string",
            "format": "uri"
        },
        "type": {
            "description": "The value of type must always match the string 'RegulatoryNotification'",
            "type": "string",
            "enum": ["RegulatoryNotification"],
            "default": "RegulatoryNotification"
        },
        "messageSender": {
            "description": "The value of messageSender should be expressed as an object that specifies the gs1:partyGLN property - or as a corresponding GS1 Digital Link URI that includes the pattern /417/ followed by a 13 digit GLN value",
            "$ref": "#/$defs/OrganizationIdentifier"
        },
        "messageRecipient": {
            "description": "The value of messageRecipient should be expressed as an object that specifies the gs1:partyGLN property - or as a corresponding GS1 Digital Link URI that includes the pattern /417/ followed by a 13 digit GLN value",
            "$ref": "#/$defs/OrganizationIdentifier"
        },
        "regulatoryInformation": {
            "description": "The value of the regulatoryInformation property must be an object that validates against the definition for RegulatoryInformationObject - or an array list of such objects",
            "oneOf": [
                {
                    "type": "array",
                    "items": {
                        "$ref": "#/$defs/RegulatoryInformationObject"
                    }
                },
                {
                    "type": "object",
                    "$ref": "#/$defs/RegulatoryInformationObject"
                }
            ]
        }
    },
    "required": [
        "type",
        "messageSender",
        "messageRecipient",
        "regulatoryInformation",
        "@context"
    ]
}