{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://schema.manifest.build/definitions/entity-schema.json",
    "title": "Entity Schema",
    "description": "An entity in your system. Doc: https://manifest.build/docs/entities",
    "type": "object",
    "properties": {
        "className": {
            "description": "The class name. Used widely on the admin panel. Default: class name.",
            "type": "string"
        },
        "nameSingular": {
            "description": "The singular lowercase name of your entity. Used widely on the admin panel. Default: singular lowercase name.",
            "type": "string"
        },
        "namePlural": {
            "description": "The plural lowercase name of your entity. Used widely on the admin panel. Default: plural lowercase name.",
            "type": "string"
        },
        "slug": {
            "description": "The kebab-case slug of the entity that will define API endpoints. Default: plural dasherized name.",
            "type": "string"
        },
        "mainProp": {
            "description": "The main prop of the entity. Used widely on the admin panel. Default: first string field.",
            "type": "string"
        },
        "seedCount": {
            "description": "The number of entities to seed when running the seed command. Default: 50.",
            "type": "integer"
        },
        "authenticable": {
            "description": "Whether the entity is authenticable. Doc: https://manifest.build/docs/auth",
            "type": "boolean"
        },
        "single": {
            "description": "Whether the entity is a single type instead of a collection. Doc: https://manifest.build/docs/entities#singles",
            "type": "boolean",
            "default": false
        },
        "properties": {
            "description": "The properties of the entity. Doc: https://manifest.build/docs/entities",
            "type": "array",
            "items": {
                "$ref": "property-schema.json"
            }
        },
        "belongsTo": {
            "description": "The ManyToOne relationships of the entity. Doc: https://manifest.build/docs/relations",
            "type": "array",
            "items": {
                "$ref": "relationship-schema.json"
            }
        },
        "belongsToMany": {
            "description": "The ManyToMany relationships of the entity. Doc: https://manifest.build/docs/relations",
            "type": "array",
            "items": {
                "$ref": "relationship-schema.json"
            }
        },
        "policies": {
            "description": "The policies of the entity. Doc: https://manifest.build/docs/policies",
            "type": "object",
            "$ref": "./policies/policies-schema.json"
        },
        "validation": {
            "description": "Validation object for the properties. Doc: https://manifest.build/docs/validation",
            "type": "object",
            "properties": {
                "*": {
                    "$ref": "./validation-schema.json"
                }
            }
        },
        "hooks": {
            "description": "The hooks related to entity records events. Doc: https://manifest.build/docs/hooks",
            "type": "object",
            "$ref": "./hooks/hooks-schema.json"
        },
        "middlewares": {
            "description": "The middlewares related to entity records events. Doc: https://manifest.build/docs/middlewares",
            "type": "object",
            "$ref": "./middlewares/middlewares-schema.json"
        }
    },
    "if": {
        "properties": {
            "single": {
                "const": true
            }
        },
        "required": ["single"]
    },
    "then": {
        "not": {
            "anyOf": [
                { "required": ["authenticable"] },
                { "required": ["mainProp"] },
                { "required": ["belongsTo"] },
                { "required": ["belongsToMany"] },
                { "required": ["seedCount"] }
            ]
        }
    },
    "else": {
        "properties": {
            "authenticable": { "type": "boolean" },
            "seedCount": { "type": "integer" },
            "mainProp": { "type": "string" },
            "belongsTo": {
                "type": "array",
                "items": {
                    "$ref": "relationship-schema.json"
                }
            },
            "belongsToMany": {
                "type": "array",
                "items": {
                    "$ref": "relationship-schema.json"
                }
            }
        }
    },
    "additionalProperties": false
}
