{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "allOf": [
        {
            "$ref": "#/definitions/base-statement"
        },
        {
            "properties": {
                "data": {
                    "items": {
                        "allOf": [
                            {
                                "$ref": "#/definitions/share-parcel-data"
                            }
                        ]
                    }
                }
            }
        }
    ],
    "definitions": {
        "base-statement": {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "type": "object",
            "properties": {
                "source_jurisdiction": {
                    "description": "Jurisdiction of the source of the data",
                    "type": "string"
                },
                "company": {
                    "$ref": "#/definitions/company"
                },
                "data": {
                    "type": "array",
                    "description": "This is an array of data objects, that is the objects which actually contain the data about the datum. Generally there will only be one element in this, although in for some types of data_types there may naturally be several releated to the same company, e.g. shareholders",
                    "items": {
                        "$ref": "#/definitions/financial-payment-data-object"
                    },
                    "additionalItems": false
                }
            },
            "required": [
                "company",
                "data"
            ]
        },
        "company": {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "description": "A company which is the subject of a statement",
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                },
                "jurisdiction": {
                    "type": "string"
                },
                "company_number": {
                    "type": "string"
                },
                "identifier": {
                    "type": "string",
                    "description": "An official identifier paired with a code for the issuer of the identifier, e.g sec/12345",
                    "pattern": "^[^/]+/[^/]+$"
                }
            },
            "required": [
                "name",
                "jurisdiction"
            ]
        },
        "financial-payment-data-object": {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "type": "object",
            "properties": {
                "data_type": {
                    "enum": [
                        "financial_payment"
                    ]
                },
                "source_url": {
                    "type": "string"
                },
                "confidence": {
                    "type": "string"
                },
                "properties": {
                    "type": "object",
                    "properties": {
                        "value": {
                            "description": "The amount transacted (e.g. 19.95)",
                            "type": "string"
                        },
                        "payee_name": {
                            "description": "The name of the payee (the entity that received the money)",
                            "type": "string"
                        },
                        "currency": {
                            "description": "The currency of the payment (three letter symbol, e.g. USD, GBP, EUR)",
                            "type": "string"
                        },
                        "date": {
                            "description": "The date on which the payment was made",
                            "type": "string",
                            "format": "date"
                        },
                        "transaction_number": {
                            "description": "The unique identifier for the transaction, scoped to this bot",
                            "type": "string"
                        },
                        "jurisdiction": {
                            "description": "The jurisdiction of the body that made the payment, eg. UK, France, Delaware, Manchester",
                            "type": "string"
                        },
                        "more_details_url": {
                            "description": "A url from which more details can be seen (may be the same as the source_url)",
                            "type": [
                                "string",
                                "null"
                            ]
                        },
                        "description": {
                            "description": "The description of the transaction as given in the raw data",
                            "type": [
                                "string",
                                "null"
                            ]
                        },
                        "expense_type": {
                            "description": "The type of expense -- can be either capital, revenue (i.e. current expenditure) or null",
                            "enum": [
                                "capital",
                                "revenue",
                                null
                            ]
                        },
                        "expense_area": {
                            "description": "category (in words) of the expenditure",
                            "type": [
                                "string",
                                "null"
                            ]
                        },
                        "entity_name": {
                            "description": "The name of the government entity that made the payment, e.g. Environment Agency",
                            "type": "string"
                        },
                        "entity_uri": {
                            "description": "A unique URL (ideally a dereferencable URI) for the government entity",
                            "type": [
                                "string",
                                "null"
                            ]
                        },
                        "department_name": {
                            "description": "The name of the government department which the entity belongs to (if relevant), e.g. Department of Health",
                            "type": [
                                "string",
                                "null"
                            ]
                        },
                        "csv_line_number": {
                            "description": "If the source for the data is a CSV file, you can optionally include the line number of the CSV from which this data was retrieved",
                            "type": [
                                "string",
                                "null"
                            ]
                        }
                    },
                    "required": [
                        "value",
                        "payee_name",
                        "date",
                        "currency"
                    ]
                }
            },
            "required": [
                "data_type",
                "properties",
                "source_url",
                "confidence"
            ]
        },
        "share-parcel-data": {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "type": "object",
            "properties": {
                "data_type": {
                    "enum": [
                        "share_parcel"
                    ]
                },
                "properties": {
                    "type": "object",
                    "required": [
                        "shareholders"
                    ],
                    "properties": {
                        "number_of_shares": {
                            "description": "Number of shares, if known",
                            "type": "integer"
                        },
                        "percentage_of_shares": {
                            "description": "Percentage of shares, if known",
                            "type": "number",
                            "maximum": 100,
                            "minimum": 0
                        },
                        "shareholders": {
                            "description": "Legal persons who own this share parcel",
                            "type": "array",
                            "minItems": 1,
                            "items": {
                                "anyOf": [
                                    {
                                        "type": "object",
                                        "name": "person",
                                        "required": [
                                            "name"
                                        ],
                                        "properties": {
                                            "name": {
                                                "description": "Name of natural person or company",
                                                "type": "string"
                                            },
                                            "jurisdiction": {
                                                "description": "Jurisdiction of registration, if company",
                                                "type": "string"
                                            },
                                            "company_number": {
                                                "description": "Company number, if company and known",
                                                "type": "string"
                                            },
                                            "identifier": {
                                                "description": "Unique identifier of person",
                                                "type": "string"
                                            },
                                            "type": {
                                                "description": "Type of person if known (company or natural person)",
                                                "enum": [
                                                    "Company",
                                                    "Person"
                                                ]
                                            },
                                            "address": {
                                                "description": "Address given for owner of parcel",
                                                "type": "string"
                                            },
                                            "address_country": {
                                                "description": "Country part of owner's address",
                                                "type": "string"
                                            }
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            },
            "required": [
                "data_type",
                "properties"
            ]
        }
    }
}