{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "OTO e-CF DGII (Compupar) · plan de configuration de sortie",
  "type": "object",
  "required": ["manifest", "ecf_plan"],
  "additionalProperties": false,
  "properties": {
    "manifest": {
      "type": "object",
      "required": [
        "generated_from", "rbac_source", "workflow_source", "doctype_source",
        "source_version", "config_name", "provider", "counts",
        "roles_rbac_utilises", "note_anti_invention"
      ],
      "additionalProperties": false,
      "properties": {
        "generated_from": { "type": "string" },
        "rbac_source": { "type": "string" },
        "workflow_source": { "type": "string" },
        "doctype_source": { "type": "string" },
        "source_version": { "type": "string" },
        "config_name": { "type": "string" },
        "provider": { "type": "string" },
        "counts": {
          "type": "object",
          "required": [
            "tipos_ecf", "tipos_en_scope", "formas_pago", "emission_events",
            "roles", "valeurs_a_confirmer"
          ],
          "additionalProperties": false,
          "properties": {
            "tipos_ecf": { "type": "integer" },
            "tipos_en_scope": { "type": "integer" },
            "formas_pago": { "type": "integer" },
            "emission_events": { "type": "integer" },
            "roles": { "type": "integer" },
            "valeurs_a_confirmer": { "type": "integer" }
          }
        },
        "roles_rbac_utilises": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["role_id", "erpnext_role_name"],
            "additionalProperties": false,
            "properties": {
              "role_id": { "type": "string" },
              "erpnext_role_name": { "type": "string" }
            }
          }
        },
        "note_anti_invention": { "type": "string" }
      }
    },
    "ecf_plan": {
      "type": "object",
      "required": [
        "name", "provider", "devise_field", "emisor", "provider_config",
        "e_ncf", "tipos_ecf", "tipos_en_scope", "formas_pago",
        "forma_pago_defaut", "moneda", "taxes", "emission_events", "field_map"
      ],
      "additionalProperties": false,
      "properties": {
        "name": { "type": "string" },
        "provider": { "type": "string" },
        "devise_field": { "type": "string" },
        "emisor": {
          "type": "object",
          "required": ["rnc_emisor", "razon_social", "source", "a_confirmer", "note"],
          "additionalProperties": false,
          "properties": {
            "rnc_emisor": { "type": ["string", "null"] },
            "razon_social": { "type": ["string", "null"] },
            "source": { "type": ["string", "null"] },
            "a_confirmer": { "type": "boolean" },
            "note": { "type": "string" }
          }
        },
        "provider_config": {
          "type": "object",
          "required": [
            "nom", "role", "endpoint_recepcion", "endpoint_aprobacion_comercial",
            "credentials_ref", "certificat_ref", "source", "a_confirmer"
          ],
          "additionalProperties": false,
          "properties": {
            "nom": { "type": "string" },
            "role": { "type": "string" },
            "endpoint_recepcion": { "type": ["string", "null"] },
            "endpoint_aprobacion_comercial": { "type": ["string", "null"] },
            "credentials_ref": { "type": "string" },
            "certificat_ref": { "type": "string" },
            "source": { "type": ["string", "null"] },
            "a_confirmer": { "type": "boolean" }
          }
        },
        "e_ncf": {
          "type": "object",
          "required": ["prefix", "longueur", "regex", "structure", "note_secuencia", "source"],
          "additionalProperties": false,
          "properties": {
            "prefix": { "type": "string" },
            "longueur": { "type": "integer" },
            "regex": { "type": "string" },
            "structure": { "type": "string" },
            "note_secuencia": { "type": "string" },
            "source": { "type": "string" }
          }
        },
        "tipos_ecf": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["code", "label", "en_scope"],
            "additionalProperties": false,
            "properties": {
              "code": { "type": "string", "pattern": "^[0-9]{2}$" },
              "label": { "type": "string" },
              "en_scope": { "type": "boolean" }
            }
          }
        },
        "tipos_en_scope": {
          "type": "array",
          "items": { "type": "string", "pattern": "^[0-9]{2}$" }
        },
        "formas_pago": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["code", "label"],
            "additionalProperties": false,
            "properties": {
              "code": { "type": "string" },
              "label": { "type": "string" }
            }
          }
        },
        "forma_pago_defaut": {
          "type": "object",
          "required": ["code", "motif", "source"],
          "additionalProperties": false,
          "properties": {
            "code": { "type": "string" },
            "motif": { "type": "string" },
            "source": { "type": "string" }
          }
        },
        "moneda": {
          "type": "object",
          "required": ["tipo_moneda_field", "options", "options_source", "tipo_cambio", "note_cambio", "source", "a_confirmer"],
          "additionalProperties": false,
          "properties": {
            "tipo_moneda_field": { "type": "string" },
            "options": {
              "type": "array",
              "items": { "type": "string" }
            },
            "options_source": { "type": "string" },
            "tipo_cambio": { "type": ["number", "string", "null"] },
            "note_cambio": { "type": "string" },
            "source": { "type": ["string", "null"] },
            "a_confirmer": { "type": "boolean" }
          }
        },
        "taxes": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["code", "label", "taux_pct", "source", "a_confirmer", "note"],
            "additionalProperties": false,
            "properties": {
              "code": { "type": "string" },
              "label": { "type": "string" },
              "taux_pct": { "type": ["number", "string", "null"] },
              "source": { "type": ["string", "null"] },
              "a_confirmer": { "type": "boolean" },
              "note": { "type": "string" }
            }
          }
        },
        "emission_events": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "update_value", "tipo_ecf", "base_field", "role_id",
              "erpnext_role_name", "libelle", "a_confirmer"
            ],
            "additionalProperties": false,
            "properties": {
              "update_value": { "type": "string" },
              "tipo_ecf": { "type": ["string", "null"], "pattern": "^[0-9]{2}$" },
              "base_field": { "type": "string" },
              "role_id": { "type": "string" },
              "erpnext_role_name": { "type": "string" },
              "libelle": { "type": "string" },
              "a_confirmer": { "type": "boolean" }
            }
          }
        },
        "field_map": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["dossier_field", "ecf_element", "note"],
            "additionalProperties": false,
            "properties": {
              "dossier_field": { "type": "string" },
              "ecf_element": { "type": "string" },
              "note": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
