{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://oto-enterprise-os-dtp/legal/confotur_application.schema.json",
  "title": "Bundle fixture DocType 'CONFOTUR Application' genere depuis confotur_spec.json + rbac_50_roles.json + workflow_vente_spec.json",
  "description": "Contrat de sortie du generateur confotur_application_gen.py. Valide par le validateur maison Publiciste (zero pip) dans le job CI legal-confotur-tests.",
  "type": "object",
  "additionalProperties": false,
  "required": ["manifest", "doctype"],
  "properties": {
    "manifest": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "generated_from",
        "rbac_source",
        "workflow_source",
        "source_version",
        "rbac_version",
        "workflow_version",
        "doctype_name",
        "custom",
        "is_submittable",
        "counts",
        "module_a_confirmer",
        "doctypes_lies_a_confirmer",
        "roles_rbac_utilises",
        "depot_events",
        "note_anti_invention",
        "hand_off_vps"
      ],
      "properties": {
        "generated_from": { "type": "string", "const": "confotur_spec.json" },
        "rbac_source": { "type": "string", "const": "rbac_50_roles.json" },
        "workflow_source": { "type": "string", "const": "crm/workflow_vente/workflow_vente_spec.json" },
        "source_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
        "rbac_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
        "workflow_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
        "doctype_name": { "type": "string", "const": "CONFOTUR Application" },
        "custom": { "type": "boolean" },
        "is_submittable": { "type": "boolean" },
        "counts": {
          "type": "object",
          "additionalProperties": false,
          "required": ["fields", "data_fields", "sections", "permissions", "roles", "depot_events"],
          "properties": {
            "fields": { "type": "integer", "minimum": 3 },
            "data_fields": { "type": "integer", "minimum": 2 },
            "sections": { "type": "integer", "minimum": 1 },
            "permissions": { "type": "integer", "minimum": 1 },
            "roles": { "type": "integer", "minimum": 1 },
            "depot_events": { "type": "integer", "minimum": 1 }
          }
        },
        "module_a_confirmer": { "type": "string", "minLength": 1 },
        "doctypes_lies_a_confirmer": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        },
        "roles_rbac_utilises": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["role_id", "erpnext_role_name", "portail", "permissions", "custom"],
            "properties": {
              "role_id": { "type": "string", "minLength": 1 },
              "erpnext_role_name": { "type": "string", "pattern": "^OTO " },
              "portail": { "type": "string", "minLength": 1 },
              "permissions": {
                "type": "array",
                "minItems": 1,
                "uniqueItems": true,
                "items": { "type": "string", "enum": ["read", "write", "create", "submit", "cancel", "amend", "delete", "print", "email", "report", "import", "export", "share"] }
              },
              "custom": { "type": "boolean" }
            }
          }
        },
        "depot_events": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["action", "next_state", "update_value", "role_id", "erpnext_role_name", "portail"],
            "properties": {
              "action": { "type": "string", "minLength": 1 },
              "next_state": { "type": "string", "minLength": 1 },
              "update_value": { "type": "string", "pattern": "^confotur" },
              "role_id": { "type": "string", "minLength": 1 },
              "erpnext_role_name": { "type": "string", "pattern": "^OTO " },
              "portail": { "type": "string", "minLength": 1 }
            }
          }
        },
        "note_anti_invention": { "type": "string", "minLength": 1 },
        "hand_off_vps": { "type": "string", "minLength": 1 }
      }
    },
    "doctype": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "doctype",
        "name",
        "module",
        "custom",
        "is_submittable",
        "naming_rule",
        "autoname",
        "title_field",
        "search_fields",
        "track_changes",
        "track_seen",
        "editable_grid",
        "engine",
        "field_order",
        "fields",
        "permissions"
      ],
      "properties": {
        "doctype": { "type": "string", "const": "DocType" },
        "name": { "type": "string", "const": "CONFOTUR Application" },
        "module": { "type": "string", "minLength": 1 },
        "custom": { "$ref": "#/definitions/flag" },
        "is_submittable": { "$ref": "#/definitions/flag" },
        "naming_rule": { "type": "string", "minLength": 1 },
        "autoname": { "type": "string", "minLength": 1 },
        "title_field": { "type": "string", "minLength": 1 },
        "search_fields": { "type": "string", "minLength": 1 },
        "track_changes": { "$ref": "#/definitions/flag" },
        "track_seen": { "$ref": "#/definitions/flag" },
        "editable_grid": { "$ref": "#/definitions/flag" },
        "engine": { "type": "string", "const": "InnoDB" },
        "field_order": {
          "type": "array",
          "minItems": 3,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        },
        "fields": {
          "type": "array",
          "minItems": 3,
          "items": { "$ref": "#/definitions/docfield" }
        },
        "permissions": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/definitions/docperm" }
        }
      }
    }
  },
  "definitions": {
    "flag": { "type": "integer", "enum": [0, 1] },
    "docfield": {
      "type": "object",
      "additionalProperties": false,
      "required": ["fieldname", "fieldtype"],
      "properties": {
        "fieldname": { "type": "string", "pattern": "^[a-z0-9_]+$" },
        "fieldtype": {
          "type": "string",
          "enum": ["Section Break", "Column Break", "Data", "Select", "Link", "Date", "Datetime", "Small Text", "Text", "Check"]
        },
        "label": { "type": "string", "minLength": 1 },
        "options": { "type": "string" },
        "default": { "type": "string" },
        "reqd": { "$ref": "#/definitions/flag" },
        "read_only": { "$ref": "#/definitions/flag" },
        "in_list_view": { "$ref": "#/definitions/flag" },
        "in_standard_filter": { "$ref": "#/definitions/flag" },
        "hidden": { "$ref": "#/definitions/flag" },
        "bold": { "$ref": "#/definitions/flag" }
      }
    },
    "docperm": {
      "type": "object",
      "additionalProperties": false,
      "required": ["role", "permlevel"],
      "properties": {
        "role": { "type": "string", "pattern": "^OTO " },
        "permlevel": { "type": "integer", "minimum": 0 },
        "read": { "$ref": "#/definitions/flag" },
        "write": { "$ref": "#/definitions/flag" },
        "create": { "$ref": "#/definitions/flag" },
        "submit": { "$ref": "#/definitions/flag" },
        "cancel": { "$ref": "#/definitions/flag" },
        "amend": { "$ref": "#/definitions/flag" },
        "delete": { "$ref": "#/definitions/flag" },
        "print": { "$ref": "#/definitions/flag" },
        "email": { "$ref": "#/definitions/flag" },
        "report": { "$ref": "#/definitions/flag" },
        "import": { "$ref": "#/definitions/flag" },
        "export": { "$ref": "#/definitions/flag" },
        "share": { "$ref": "#/definitions/flag" }
      }
    }
  }
}
