{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "https://frontastic.cloud/json/library/common",
    "title": "Common Schema Elements",
    "description": "Definitions of Common Elements in Frontastic Schemas",

    "definitions": {
        "schema": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "fields": {
                        "$ref": "#/definitions/fields"
                    }
                },
                "required": ["name", "fields"]
            }
        },

        "fields": {
            "type": "array",
            "items": {
                "oneOf": [
                    {
                        "allOf": [
                            {
                                "type": "object",
                                "properties": {
                                    "type": {
                                        "enum": [
                                            "boolean",
                                            "custom",
                                            "dataSource",
                                            "decimal",
                                            "dynamic-filter",
                                            "enum",
                                            "integer",
                                            "json",
                                            "markdown",
                                            "media",
                                            "node",
                                            "number",
                                            "reference",
                                            "stream",
                                            "string",
                                            "text",
                                            "tree",
                                            "instant",
                                            "group",
                                            "image",
                                            "description",
                                            "tastic",
                                            "encrypted"
                                        ]
                                    }
                                }
                            },
                            { "$ref": "https://frontastic.cloud/json/library/implications#/definitions/match-field-type-with-corresponding-subschema" }
                        ]
                    }
                ]
            }
        },


        "field": {
            "type": "object",
            "properties": {
                "label": {
                    "type": "string"
                },
                "description": {
                    "type": "string"
                },
                "field": {
                    "type": "string",
                    "not": {
                        "enum": [
                            "id",
                            "sequence",
                            "locale",
                            "is_deleted",
                            "password",
                            "token"
                        ]
                    }
                },
                "streamType": {
                    "$comment": "TODO: Define dependency to type?",
                    "type": "string"
                },
                "dataSourceType": {
                    "$comment": "TODO: Define dependency to type?",
                    "type": "string"
                },
                "dynamicFilterEndpoint": {
                    "type": "string",
                    "pattern": "^/"
                },
                "customAppType": {
                    "$comment": "TODO: Define dependency to type?",
                    "type": "string"
                },
                "default": {
                    "$comment": "Value type has to be as the same as the 'type' property"
                },
                "options": {
                    "$comment": "Any kind of options supported by the field type",
                    "type": "object"
                },
                "values": {
                    "$comment": "Value set for 'enum' type",
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "value": {
                                "type": "string"
                            },
                            "name": {
                                "type": "string"
                            }
                        },
                        "required": ["name", "value"]
                    }
                },

                "translatable": {
                    "type": "boolean"
                },
                "required": {
                    "type": "boolean"
                },
                "format": {
                    "type": "string",
                    "enum": [
                        "url",
                        "email",
                        "hex"
                    ]
                },
                "type": {
                    "type": "string"
                },
                "minLength": {
                    "type": "integer"
                },
                "maxLength": {
                    "type": "integer"
                },

                "$comment": {
                    "@comment": "Allow json-schema style comments in our schemas",
                    "type": "string"
                }
            },
            "$ref": "https://frontastic.cloud/json/library/implications#/definitions/multiple-field-types-imply-multiple-attributes-is-required"
        },
        "group": {
            "type": "object",
            "properties": {
                "label": {
                    "type": "string"
                },
                "description": {
                    "type": "string"
                },
                "field": {
                    "type": "string"
                },
                "itemLabelField": {
                    "type": "string"
                },
                "min": {
                    "type": "integer"
                },
                "max": {
                    "type": "integer"
                },
                "fields": {
                    "$ref": "#/definitions/fields"
                },

                "$comment": {
                    "@comment": "Allow json-schema style comments in our schemas",
                    "type": "string"
                }
            },
            "$ref": "https://frontastic.cloud/json/library/implications#/definitions/group-type-implies-label-field-and-fields-are-required"
        },
        "tastic":{
            "$comment": "Allow nesting of tastics",

            "type": "object",
            "properties": {
                "tasticType":{
                    "type": "string"
                },
                "tasticData":{
                    "type": "object"
                },
                "$comment": {
                    "@comment": "Allow json-schema style comments in our schemas",
                    "type": "string"
                }
            },
            "$ref": "https://frontastic.cloud/json/library/implications#/definitions/tastic-type-implies-label-is-required"
        },
        "image": {
            "$comment": "Illustrating image as part of the input form",

            "type": "object",
            "properties": {
                "url": {
                    "type": "string"
                },
                "$comment": {
                    "@comment": "Allow json-schema style comments in our schemas",
                    "type": "string"
                }
            },
            "$ref": "https://frontastic.cloud/json/library/implications#/definitions/image-type-implies-url-is-required"
        },
        "description": {
            "$comment": "Illustrating description as part of the input form",

            "type": "object",
            "properties": {
                "text": {
                    "type": "string"
                },
                "$comment": {
                    "@comment": "Allow json-schema style comments in our schemas",
                    "type": "string"
                }
            },
            "$ref": "https://frontastic.cloud/json/library/implications#/definitions/description-type-implies-text-is-required"
        }
    }
}
