{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Evento de Retorno",
    "type": "object",
    "properties": {
        "identificacion": {
            "description": "Identificación",
            "type": "object",
            "properties": {
                "version": {
                    "type": "integer",
                    "description": "Versión",
                    "const": 1
                },
                "ambiente": {
                    "type": "string",
                    "description": "Ambiente de destino",
                    "enum": [
                        "00",
                        "01"
                    ]
                },
                "tipoModelo": {
                    "type": "number",
                    "description": "Modelo de Facturación",
                    "enum": [
                        1,
                        2
                    ]
                },
                "tipoOperacion": {
                    "type": "integer",
                    "description": "Tipo de Transmisión",
                    "enum": [
                        1,
                        2
                    ]
                },
                "tipoEvento": {
                    "description": "Tipo de Evento",
                    "type": "string",
                    "const": "18"
                },
                "tipoContingencia": {
                    "description": "Tipo de Contingencia",
                    "type": [
                        "integer",
                        "null"
                    ],
                    "enum": [
                        null,
                        1,
                        2,
                        3,
                        4,
                        5
                    ]
                },
                "motivoContin": {
                    "description": "Motivo de Contingencia",
                    "type": [
                        "string",
                        "null"
                    ],
                    "maxLength": 500,
                    "minLength": 1
                },
                "codigoGeneracion": {
                    "type": "string",
                    "description": "Código de Generación",
                    "maxLength": 36,
                    "minLength": 36,
                    "pattern": "^[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}$"
                },
                "fecEmi": {
                    "type": "string",
                    "description": "Fecha de Generación",
                    "format": "date"
                },
                "horEmi": {
                    "type": "string",
                    "description": "Hora de Generación",
                    "pattern": "^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$"
                },
                "fusion": {
                    "description": "Fusiones y otros",
                    "type": [
                        "string",
                        "null"
                    ],
                    "minLength": 9,
                    "maxLength": 14
                },
                "tipoMoneda": {
                    "type": "string",
                    "description": "Tipo de Moneda",
                    "enum": [
                        "USD"
                    ]
                }
            },
            "allOf": [
                {
                    "if": {
                        "properties": {
                            "tipoOperacion": {
                                "const": 1
                            }
                        }
                    },
                    "then": {
                        "properties": {
                            "tipoContingencia": {
                                "type": "null"
                            },
                            "motivoContin": {
                                "type": "null"
                            }
                        }
                    },
                    "else": {
                        "properties": {
                            "tipoModelo": {
                                "const": 2
                            },
                            "tipoContingencia": {
                                "type": "integer"
                            }
                        }
                    }
                },
                {
                    "if": {
                        "properties": {
                            "tipoContingencia": {
                                "const": 5
                            }
                        }
                    },
                    "then": {
                        "properties": {
                            "motivoContin": {
                                "type": "string"
                            }
                        }
                    },
                    "else": {
                        "properties": {
                            "motivoContin": {
                                "type": "null"
                            }
                        }
                    }
                }
            ],
            "additionalProperties": false,
            "required": [
                "version",
                "ambiente",
                "tipoModelo",
                "tipoOperacion",
                "tipoEvento",
                "tipoContingencia",
                "motivoContin",
                "codigoGeneracion",
                "fecEmi",
                "horEmi",
                "fusion",
                "tipoMoneda"
            ]
        },
        "documentoRelacionado": {
            "description": "Documentos Relacionados",
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "tipoDocumento": {
                        "type": "string",
                        "description": "Tipo de DTE"
                    },
                    "codigoGeneracion": {
                        "description": "Código de Generación del DTE",
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 36
                    },
                    "fechaEmision": {
                        "description": "Fecha de Generación del DTE",
                        "type": "string",
                        "format": "date"
                    }
                },
                "additionalProperties": false,
                "required": [
                    "tipoDocumento",
                    "codigoGeneracion",
                    "fechaEmision"
                ]
            },
            "minItems": 1,
            "maxItems": 50
        },
        "emisor": {
            "type": "object",
            "description": "Información del Emisor",
            "properties": {
                "nit": {
                    "description": "NIT (Emisor)",
                    "type": "string",
                    "maxLength": 14
                },
                "nombre": {
                    "type": "string",
                    "description": "Nombre (Emisor)",
                    "maxLength": 250,
                    "minLength": 1
                },
                "codEstableMH": {
                    "description": "Código del establecimiento asignado por el MH",
                    "type": "string",
                    "maxLength": 4,
                    "minLength": 4
                },
                "codEstable": {
                    "description": "Código del establecimiento asignado por el contribuyente",
                    "type": [
                        "string",
                        "null"
                    ],
                    "minLength": 1,
                    "maxLength": 10
                },
                "codPuntoVentaMH": {
                    "description": "Código del Punto de Venta (Emisor) asignado por el MH",
                    "type": "string",
                    "maxLength": 4,
                    "minLength": 4
                },
                "codPuntoVenta": {
                    "description": "Código del Punto de Venta (Emisor) asignado por el contribuyente",
                    "type": [
                        "string",
                        "null"
                    ],
                    "minLength": 1,
                    "maxLength": 15
                },
                "recintoFiscal": {
                    "description": "Recinto Fiscal",
                    "type": [
                        "string",
                        "null"
                    ],
                    "maxLength": 2,
                    "minLength": 2
                },
                "tipoRegimen": {
                    "description": "Tipo de Regimen",
                    "type": [
                        "string",
                        "null"
                    ],
                    "minLength": 1,
                    "maxLength": 4
                },
                "regimen": {
                    "description": "Régimen de exportación",
                    "type": [
                        "string",
                        "null"
                    ],
                    "minLength": 1,
                    "maxLength": 13
                },
                "tipoItemExpor": {
                    "description": "Tipo de exportacion",
                    "type": [
                        "integer",
                        "null"
                    ]
                }
            },
            "additionalProperties": false,
            "required": [
                "nit",
                "nombre",
                "codEstableMH",
                "codEstable",
                "codPuntoVentaMH",
                "codPuntoVenta",
                "recintoFiscal",
                "tipoRegimen",
                "regimen",
                "tipoItemExpor"
            ]
        },
        "documento": {
            "type": [
                "object",
                "null"
            ],
            "description": "Información del documento",
            "properties": {
                "tipoDocumento": {
                    "type": [
                        "string",
                        "null"
                    ],
                    "description": "Tipo de documento de identificación (Receptor)"
                },
                "numDocumento": {
                    "type": [
                        "null",
                        "string"
                    ],
                    "description": "Número de documento de Identificación (Receptor)",
                    "minLength": 1,
                    "maxLength": 20
                },
                "nombre": {
                    "type": [
                        "null",
                        "string"
                    ],
                    "description": "Nombre (Receptor)",
                    "minLength": 1,
                    "maxLength": 250
                },
                "codPais": {
                    "type": [
                        "null",
                        "string"
                    ],
                    "description": "Código de país (receptor)"
                },
                "nombrePais": {
                    "type": [
                        "null",
                        "string"
                    ],
                    "description": "País destino de la exportación (receptor)",
                    "minLength": 3,
                    "maxLength": 50
                },
                "telefono": {
                    "type": [
                        "null",
                        "string"
                    ],
                    "description": "Teléfono (Receptor)",
                    "minLength": 8,
                    "maxLength": 30
                },
                "correo": {
                    "type": [
                        "null",
                        "string"
                    ],
                    "description": "Correo electrónico (Receptor)",
                    "maxLength": 100,
                    "minLength": 1
                }
            },
            "additionalProperties": false,
            "required": [
                "tipoDocumento",
                "numDocumento",
                "nombre",
                "codPais",
                "nombrePais",
                "telefono",
                "correo"
            ]
        },
        "ventaTercero": {
            "description": "Ventas por Cuenta de Terceros",
            "type": [
                "object",
                "null"
            ],
            "properties": {
                "nit": {
                    "type": [
                        "string",
                        "null"
                    ],
                    "description": "NIT por Cuenta de Terceros",
                    "minLength": 1,
                    "maxLength": 20
                },
                "nombre": {
                    "type": [
                        "string",
                        "null"
                    ],
                    "description": "Nombre, denominación o razón social del Tercero",
                    "minLength": 1,
                    "maxLength": 250
                },
                "codDomiciliado": {
                    "description": "Domicilio Fiscal",
                    "type": [
                        "integer",
                        "null"
                    ]
                }
            },
            "additionalProperties": false,
            "required": [
                "nit",
                "nombre",
                "codDomiciliado"
            ]
        },
        "compraTercero": {
            "description": "Información de Compras por cuenta de terceros",
            "type": [
                "object",
                "null"
            ],
            "properties": {
                "numDocumento": {
                    "description": "Número de documento de Identificación del tercero",
                    "type": [
                        "string",
                        "null"
                    ],
                    "minLength": 1,
                    "maxLength": 20
                },
                "nombre": {
                    "description": "Nombre del Tercero",
                    "type": [
                        "string",
                        "null"
                    ],
                    "minLength": 1,
                    "maxLength": 250
                }
            },
            "additionalProperties": false,
            "required": [
                "numDocumento",
                "nombre"
            ]
        },
        "cuerpoDocumento": {
            "type": "array",
            "description": "Cuerpo del Documento",
            "items": {
                "type": "object",
                "properties": {
                    "numItem": {
                        "type": "integer",
                        "description": "N° de ítem",
                        "minimum": 1,
                        "maximum": 2000
                    },
                    "tipoItem": {
                        "type": "integer",
                        "description": "Tipo de ítem"
                    },
                    "codigoGeneracion": {
                        "description": "Código de Generación del DTE",
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 36
                    },
                    "cantidad": {
                        "type": "number",
                        "description": "Cantidad",
                        "exclusiveMaximum": 100000000000,
                        "exclusiveMinimum": 0,
                        "multipleOf": 1e-08
                    },
                    "precioUni": {
                        "type": "number",
                        "description": "Precio Unitario",
                        "exclusiveMaximum": 100000000000,
                        "multipleOf": 1e-08
                    },
                    "descripcion": {
                        "description": "Descripcion",
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 1500
                    },
                    "codigo": {
                        "description": "Código",
                        "type": [
                            "string",
                            "null"
                        ],
                        "minLength": 1,
                        "maxLength": 25
                    },
                    "uniMedida": {
                        "type": "integer",
                        "description": "Unidad de Medida",
                        "minimum": 1,
                        "maximum": 99
                    },
                    "montoDescu": {
                        "type": "number",
                        "description": "Descuento por ítem",
                        "minimum": 0,
                        "exclusiveMaximum": 100000000000,
                        "multipleOf": 1e-08
                    },
                    "codTributo": {
                        "description": "Tributo sujeto a cálculo de IVA",
                        "type": [
                            "string",
                            "null"
                        ],
                        "maxLength": 2,
                        "minLength": 2
                    },
                    "ventaNoSuj": {
                        "type": "number",
                        "description": "Ventas no Sujetas",
                        "minimum": 0,
                        "exclusiveMaximum": 100000000000,
                        "multipleOf": 1e-08
                    },
                    "ventaExenta": {
                        "type": "number",
                        "description": "Ventas Exentas",
                        "minimum": 0,
                        "exclusiveMaximum": 100000000000,
                        "multipleOf": 1e-08
                    },
                    "ventaGravada": {
                        "type": "number",
                        "description": "Ventas Gravadas",
                        "minimum": 0,
                        "exclusiveMaximum": 100000000000,
                        "multipleOf": 1e-08
                    },
                    "compra": {
                        "type": "number",
                        "description": "Ventas",
                        "minimum": 0,
                        "exclusiveMaximum": 100000000000,
                        "multipleOf": 1e-08
                    },
                    "tributos": {
                        "description": "Código del Tributo",
                        "type": [
                            "array",
                            "null"
                        ],
                        "items": {
                            "type": [
                                "string",
                                "null"
                            ],
                            "maxLength": 2,
                            "minLength": 2
                        },
                        "minItems": 1,
                        "uniqueItems": true
                    },
                    "psv": {
                        "type": "number",
                        "description": "Precio Sugerido de Venta",
                        "minimum": 0,
                        "exclusiveMaximum": 100000000000,
                        "multipleOf": 1e-08
                    },
                    "ivaItem": {
                        "type": "number",
                        "description": "IVA por ítem",
                        "minimum": 0,
                        "exclusiveMaximum": 100000000000,
                        "multipleOf": 1e-08
                    },
                    "noGravado": {
                        "type": "number",
                        "description": "Cargos/Abonos que no afectan la base imponible",
                        "exclusiveMaximum": 100000000000,
                        "exclusiveMinimum": -100000000000,
                        "multipleOf": 1e-08
                    },
                    "seguro": {
                        "type": "number",
                        "description": "Seguro",
                        "exclusiveMaximum": 100000000000,
                        "exclusiveMinimum": -100000000000,
                        "multipleOf": 1e-08
                    },
                    "flete": {
                        "type": "number",
                        "description": "Flete",
                        "exclusiveMaximum": 100000000000,
                        "exclusiveMinimum": -100000000000,
                        "multipleOf": 1e-08
                    },
                    "ivaRete": {
                        "type": "number",
                        "description": "IVA Retenido",
                        "minimum": 0,
                        "multipleOf": 0.01
                    },
                    "reteRenta": {
                        "type": "number",
                        "description": "Retención Renta",
                        "minimum": 0,
                        "exclusiveMaximum": 100000000000,
                        "multipleOf": 0.01
                    }
                },
                "additionalProperties": false,
                "required": [
                    "numItem",
                    "tipoItem",
                    "codigoGeneracion",
                    "cantidad",
                    "precioUni",
                    "descripcion",
                    "montoDescu",
                    "codTributo",
                    "ventaNoSuj",
                    "ventaExenta",
                    "ventaGravada",
                    "compra",
                    "tributos",
                    "psv",
                    "ivaItem",
                    "noGravado",
                    "seguro",
                    "flete",
                    "ivaRete",
                    "reteRenta"
                ]
            },
            "minItems": 1,
            "maxItems": 2000
        },
        "resumen": {
            "type": "object",
            "description": "Resumen",
            "properties": {
                "totalNoSuj": {
                    "type": "number",
                    "description": "Total de Operaciones no Sujetas",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "totalExenta": {
                    "type": "number",
                    "description": "Total de Operaciones exentas",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "totalGravada": {
                    "type": "number",
                    "description": "Total de Operaciones Gravadas",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "totalCompraExcluidos": {
                    "type": "number",
                    "description": "Total Compras a Sujetos Excluidos ",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "subTotalVentas": {
                    "type": "number",
                    "description": "Suma de Operaciones sin Impuestos",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "tributos": {
                    "type": [
                        "array",
                        "null"
                    ],
                    "uniqueItems": true,
                    "description": "Resumen Código de Tributo",
                    "items": {
                        "type": "object",
                        "properties": {
                            "codigo": {
                                "description": "Resumen Código de Tributo",
                                "type": "string",
                                "minLength": 2,
                                "maxLength": 2
                            },
                            "descripcion": {
                                "description": "Nombre del Tributo",
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 300
                            },
                            "valor": {
                                "description": "Valor del Tributo",
                                "type": "number",
                                "minimum": 0,
                                "exclusiveMaximum": 100000000000,
                                "multipleOf": 0.01
                            }
                        },
                        "additionalProperties": false,
                        "required": [
                            "codigo",
                            "descripcion",
                            "valor"
                        ]
                    }
                },
                "totalSeguro": {
                    "type": [
                        "number",
                        "null"
                    ],
                    "description": "Seguro",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "totalFlete": {
                    "type": [
                        "number",
                        "null"
                    ],
                    "description": "Flete",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "montoTotalOperacion": {
                    "type": "number",
                    "description": "Monto Total de la Operación",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "ivaRete": {
                    "type": "number",
                    "description": "IVA Retenido",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "reteRenta": {
                    "description": "Retencion Renta",
                    "type": [
                        "number",
                        "null"
                    ],
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "totalNoGravado": {
                    "type": "number",
                    "description": "Total Cargos/Abonos que no afectan la base imponible",
                    "exclusiveMaximum": 100000000000,
                    "exclusiveMinimum": -100000000000,
                    "multipleOf": 0.01
                },
                "totalPagar": {
                    "type": "number",
                    "description": "Total a Pagar",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "totalLetras": {
                    "type": [
                        "string",
                        "null"
                    ],
                    "description": "Valor en Letras",
                    "minLength": 8,
                    "maxLength": 200
                },
                "totalNoOnerosas": {
                    "type": "number",
                    "description": "Transferencias de bienes no onerosas",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "totalIva": {
                    "type": "number",
                    "description": "IVA 13%",
                    "minimum": 0,
                    "exclusiveMaximum": 100000000000,
                    "multipleOf": 0.01
                },
                "saldoFavor": {
                    "type": "number",
                    "description": "Saldo a Favor",
                    "maximum": 0,
                    "exclusiveMinimum": -100000000000,
                    "multipleOf": 0.01
                }
            },
            "additionalProperties": false,
            "required": [
                "totalNoSuj",
                "totalExenta",
                "totalGravada",
                "totalCompraExcluidos",
                "subTotalVentas",
                "tributos",
                "totalSeguro",
                "totalFlete",
                "montoTotalOperacion",
                "ivaRete",
                "reteRenta",
                "totalNoGravado",
                "totalPagar",
                "totalLetras",
                "totalNoOnerosas",
                "totalIva",
                "saldoFavor"
            ]
        },
        "apendice": {
            "description": "Apéndice",
            "type": [
                "array",
                "null"
            ],
            "items": {
                "type": "object",
                "properties": {
                    "campo": {
                        "type": "string",
                        "description": "Nombre del campo",
                        "maxLength": 25
                    },
                    "etiqueta": {
                        "type": "string",
                        "description": "Descripción",
                        "maxLength": 50
                    },
                    "valor": {
                        "type": "string",
                        "description": "Valor/Dato",
                        "maxLength": 150
                    }
                },
                "additionalProperties": false,
                "required": [
                    "campo",
                    "etiqueta",
                    "valor"
                ]
            },
            "minItems": 1,
            "maxItems": 10
        }
    },
    "oneOf": [
        {
            "properties": {
                "ventaTercero": {
                    "type": [
                        "object"
                    ]
                },
                "compraTercero": {
                    "type": [
                        "null"
                    ]
                }
            }
        },
        {
            "properties": {
                "compraTercero": {
                    "type": [
                        "object"
                    ]
                },
                "ventaTercero": {
                    "type": [
                        "null"
                    ]
                }
            }
        },
        {
            "properties": {
                "ventaTercero": {
                    "type": [
                        "null"
                    ]
                },
                "compraTercero": {
                    "type": [
                        "null"
                    ]
                }
            }
        }
    ],
    "additionalProperties": false,
    "required": [
        "identificacion",
        "documentoRelacionado",
        "emisor",
        "documento",
        "ventaTercero",
        "compraTercero",
        "cuerpoDocumento",
        "resumen",
        "apendice"
    ]
}