{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cdn.comprobanteselectronicos.go.cr/json-schemas/v4.4/tiqueteElectronico",
  "title": "TiqueteElectronico",
  "type": "object",
  "properties": {
    "Clave": {
      "type": "string",
      "pattern": "^\\d{50}$"
    },
    "ProveedorSistemas": {
      "type": "string",
      "maxLength": 20
    },
    "CodigoActividadEmisor": {
      "type": "string",
      "minLength": 6,
      "maxLength": 6
    },
    "NumeroConsecutivo": {
      "type": "string",
      "pattern": "^\\d{20}$"
    },
    "FechaEmision": {
      "type": "string",
      "format": "date-time"
    },
    "Emisor": { "$ref": "#/$defs/EmisorType" },
    "Receptor": { "$ref": "#/$defs/ReceptorType" },
    "CondicionVenta": {
      "type": "string",
      "enum": [
        "01",
        "02",
        "03",
        "04",
        "05",
        "06",
        "07",
        "08",
        "10",
        "13",
        "14",
        "15",
        "99"
      ]
    },
    "CondicionVentaOtros": {
      "type": "string",
      "minLength": 5,
      "maxLength": 100
    },
    "PlazoCredito": {
      "type": "integer",
      "minimum": 0,
      "maximum": 99999
    },
    "DetalleServicio": {
      "type": "object",
      "properties": {
        "LineaDetalle": {
          "type": "array",
          "maxItems": 1000,
          "items": { "$ref": "#/$defs/LineaDetalleType" }
        }
      },
      "required": ["LineaDetalle"]
    },
    "OtrosCargos": {
      "type": "array",
      "maxItems": 15,
      "items": { "$ref": "#/$defs/OtrosCargosType" }
    },
    "ResumenFactura": { "$ref": "#/$defs/ResumenFacturaType" },
    "InformacionReferencia": {
      "type": "array",
      "maxItems": 10,
      "items": { "$ref": "#/$defs/InformacionReferenciaType" }
    },
    "Otros": {
      "type": "object",
      "properties": {
        "OtroTexto": {
          "type": "array",
          "items": { "$ref": "#/$defs/OtroContenidoType" }
        },
        "OtroContenido": {
          "type": "array",
          "items": { "$ref": "#/$defs/OtroContenidoType" }
        }
      }
    },
    "ds:Signature": {
      "type": "object"
    }
  },
  "required": [
    "Clave",
    "ProveedorSistemas",
    "CodigoActividadEmisor",
    "NumeroConsecutivo",
    "FechaEmision",
    "Emisor",
    "CondicionVenta",
    "ResumenFactura",
    "ds:Signature"
  ],
  "$defs": {
    "EmisorType": {
      "type": "object",
      "properties": {
        "Nombre": { "type": "string", "minLength": 5, "maxLength": 100 },
        "Identificacion": { "$ref": "#/$defs/IdentificacionType" },
        "Registrofiscal8707": { "type": "string", "maxLength": 12 },
        "NombreComercial": {
          "type": "string",
          "minLength": 3,
          "maxLength": 80
        },
        "Ubicacion": { "$ref": "#/$defs/UbicacionType" },
        "Telefono": { "$ref": "#/$defs/TelefonoType" },
        "CorreoElectronico": {
          "type": "array",
          "maxItems": 4,
          "items": { "type": "string", "maxLength": 160 }
        }
      },
      "required": ["Nombre", "Identificacion", "Ubicacion", "CorreoElectronico"]
    },
    "ReceptorType": {
      "type": "object",
      "properties": {
        "Nombre": { "type": "string", "minLength": 3, "maxLength": 100 },
        "Identificacion": { "$ref": "#/$defs/IdentificacionType" },
        "NombreComercial": {
          "type": "string",
          "minLength": 3,
          "maxLength": 80
        },
        "Ubicacion": { "$ref": "#/$defs/UbicacionType" },
        "OtrasSenasExtranjero": {
          "type": "string",
          "minLength": 5,
          "maxLength": 300
        },
        "Telefono": { "$ref": "#/$defs/TelefonoType" },
        "CorreoElectronico": { "type": "string", "maxLength": 160 }
      },
      "required": ["Nombre"]
    },
    "IdentificacionType": {
      "type": "object",
      "properties": {
        "Tipo": {
          "type": "string",
          "enum": ["01", "02", "03", "04", "05", "06"]
        },
        "Numero": { "type": "string", "maxLength": 20 }
      },
      "required": ["Tipo", "Numero"]
    },
    "UbicacionType": {
      "type": "object",
      "properties": {
        "Provincia": { "type": "integer", "minimum": 1, "maximum": 9 },
        "Canton": { "type": "integer", "minimum": 1, "maximum": 99 },
        "Distrito": { "type": "integer", "minimum": 1, "maximum": 99 },
        "Barrio": { "type": "string", "minLength": 5, "maxLength": 50 },
        "OtrasSenas": { "type": "string", "minLength": 5, "maxLength": 250 }
      },
      "required": ["Provincia", "Canton", "Distrito", "OtrasSenas"]
    },
    "TelefonoType": {
      "type": "object",
      "properties": {
        "CodigoPais": { "type": "integer", "minimum": 0, "maximum": 999 },
        "NumTelefono": {
          "type": "integer",
          "minimum": 10000000,
          "maximum": 99999999999999999999
        }
      },
      "required": ["CodigoPais", "NumTelefono"]
    },
    "LineaDetalleType": {
      "type": "object",
      "properties": {
        "NumeroLinea": { "type": "integer", "minimum": 1, "maximum": 1000 },
        "CodigoCABYS": { "type": "string", "minLength": 13, "maxLength": 13 },
        "CodigoComercial": {
          "type": "array",
          "maxItems": 5,
          "items": { "$ref": "#/$defs/CodigoType" }
        },
        "Cantidad": { "type": "number" },
        "UnidadMedida": { "type": "string" },
        "UnidadMedidaComercial": { "type": "string", "maxLength": 20 },
        "Detalle": { "type": "string", "minLength": 3, "maxLength": 200 },
        "NumeroVINoSerie": {
          "type": "array",
          "maxItems": 1000,
          "items": { "type": "string", "maxLength": 17 }
        },
        "RegistroMedicamento": { "type": "string", "maxLength": 100 },
        "FormaFarmaceutica": { "type": "string", "maxLength": 3 },
        "DetalleSurtido": { "type": "object" }, // Nested structure omitted for brevity
        "PrecioUnitario": { "$ref": "#/$defs/DecimalDineroType" },
        "MontoTotal": { "$ref": "#/$defs/DecimalDineroType" },
        "Descuento": {
          "type": "array",
          "maxItems": 5,
          "items": { "$ref": "#/$defs/DescuentoType" }
        },
        "SubTotal": { "$ref": "#/$defs/DecimalDineroType" },
        "IVACobradoFabrica": { "type": "string", "enum": ["01", "02"] },
        "BaseImponible": { "$ref": "#/$defs/DecimalDineroType" },
        "Impuesto": {
          "type": "array",
          "maxItems": 1000,
          "items": { "$ref": "#/$defs/ImpuestoType" }
        },
        "ImpuestoAsumidoEmisorFabrica": { "$ref": "#/$defs/DecimalDineroType" },
        "ImpuestoNeto": { "$ref": "#/$defs/DecimalDineroType" },
        "MontoTotalLinea": { "$ref": "#/$defs/DecimalDineroType" }
      },
      "required": [
        "NumeroLinea",
        "CodigoCABYS",
        "Cantidad",
        "UnidadMedida",
        "Detalle",
        "PrecioUnitario",
        "MontoTotal",
        "SubTotal",
        "BaseImponible",
        "Impuesto",
        "ImpuestoAsumidoEmisorFabrica",
        "ImpuestoNeto",
        "MontoTotalLinea"
      ]
    },
    "CodigoType": {
      "type": "object",
      "properties": {
        "Tipo": {
          "type": "string",
          "enum": ["01", "02", "03", "04", "99"]
        },
        "Codigo": { "type": "string", "maxLength": 20 }
      },
      "required": ["Tipo", "Codigo"]
    },
    "DescuentoType": {
      "type": "object",
      "properties": {
        "MontoDescuento": { "$ref": "#/$defs/DecimalDineroType" },
        "CodigoDescuento": {
          "type": "string",
          "enum": ["01", "02", "03", "04", "05", "06", "07", "08", "09", "99"]
        },
        "CodigoDescuentoOTRO": {
          "type": "string",
          "minLength": 5,
          "maxLength": 100
        },
        "NaturalezaDescuento": {
          "type": "string",
          "minLength": 3,
          "maxLength": 80
        }
      },
      "required": ["MontoDescuento", "CodigoDescuento"]
    },
    "ImpuestoType": {
      "type": "object",
      "properties": {
        "Codigo": {
          "type": "string",
          "enum": ["01", "02", "03", "04", "05", "06", "07", "08", "12", "99"]
        },
        "CodigoImpuestoOTRO": {
          "type": "string",
          "minLength": 5,
          "maxLength": 100
        },
        "CodigoTarifaIVA": { "type": "string" },
        "Tarifa": { "type": "number" },
        "FactorCalculoIVA": { "type": "number" },
        "DatosImpuestoEspecifico": { "type": "object" }, // Nested structure omitted for brevity
        "Monto": { "$ref": "#/$defs/DecimalDineroType" },
        "Exoneracion": { "type": "object" } // Nested structure omitted for brevity
      },
      "required": ["Codigo", "Monto"]
    },
    "OtrosCargosType": {
      "type": "object",
      "properties": {
        "TipoDocumentoOC": { "type": "string" },
        "TipoDocumentoOTROS": {
          "type": "string",
          "minLength": 5,
          "maxLength": 100
        },
        "IdentificacionTercero": { "$ref": "#/$defs/IdentificacionType" },
        "NombreTercero": { "type": "string", "minLength": 5, "maxLength": 100 },
        "Detalle": { "type": "string", "maxLength": 160 },
        "PorcentajeOC": { "type": "number" },
        "MontoCargo": { "$ref": "#/$defs/DecimalDineroType" }
      },
      "required": ["TipoDocumentoOC", "Detalle", "MontoCargo"]
    },
    "ResumenFacturaType": {
      "type": "object",
      "properties": {
        "CodigoTipoMoneda": { "$ref": "#/$defs/CodigoMonedaType" },
        "TotalServGravados": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalServExentos": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalServExonerado": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalServNoSujeto": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalMercanciasGravadas": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalMercanciasExentas": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalMercExonerada": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalMercNoSujeta": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalGravado": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalExento": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalExonerado": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalNoSujeto": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalVenta": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalDescuentos": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalVentaNeta": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalDesgloseImpuesto": {
          "type": "array",
          "maxItems": 1000,
          "items": { "$ref": "#/$defs/TotalDesgloseImpuestoType" }
        },
        "TotalImpuesto": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalImpAsumEmisorFabrica": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalIVADevuelto": { "$ref": "#/$defs/DecimalDineroType" },
        "TotalOtrosCargos": { "$ref": "#/$defs/DecimalDineroType" },
        "MedioPago": {
          "type": "array",
          "maxItems": 4,
          "items": { "$ref": "#/$defs/MedioPagoType" }
        },
        "TotalComprobante": { "$ref": "#/$defs/DecimalDineroType" }
      },
      "required": [
        "CodigoTipoMoneda",
        "TotalVenta",
        "TotalVentaNeta",
        "TotalComprobante"
      ]
    },
    "CodigoMonedaType": {
      "type": "object",
      "properties": {
        "CodigoMoneda": { "type": "string" },
        "TipoCambio": { "$ref": "#/$defs/DecimalDineroType" }
      },
      "required": ["CodigoMoneda", "TipoCambio"]
    },
    "DecimalDineroType": {
      "type": "number",
      "minimum": 0,
      "maximum": 9999999999999.99999
    },
    "TotalDesgloseImpuestoType": {
      "type": "object",
      "properties": {
        "Codigo": { "type": "string" },
        "CodigoTarifaIVA": { "type": "string" },
        "TotalMontoImpuesto": { "$ref": "#/$defs/DecimalDineroType" }
      },
      "required": ["Codigo", "TotalMontoImpuesto"]
    },
    "MedioPagoType": {
      "type": "object",
      "properties": {
        "TipoMedioPago": {
          "type": "string",
          "enum": ["01", "02", "03", "04", "05", "06", "07", "99"]
        },
        "MedioPagoOtros": {
          "type": "string",
          "minLength": 3,
          "maxLength": 100
        },
        "TotalMedioPago": { "$ref": "#/$defs/DecimalDineroType" }
      }
    },
    "InformacionReferenciaType": {
      "type": "object",
      "properties": {
        "TipoDocIR": { "type": "string" },
        "TipoDocRefOTRO": {
          "type": "string",
          "minLength": 5,
          "maxLength": 100
        },
        "Numero": { "type": "string", "maxLength": 50 },
        "FechaEmisionIR": { "type": "string", "format": "date-time" },
        "Codigo": { "type": "string" },
        "CodigoReferenciaOTRO": {
          "type": "string",
          "minLength": 5,
          "maxLength": 100
        },
        "Razon": { "type": "string", "maxLength": 180 }
      },
      "required": ["TipoDocIR", "FechaEmisionIR"]
    },
    "OtroContenidoType": {
      "type": "object",
      "properties": {
        "codigo": { "type": "string" },
        "value": { "type": "string", "maxLength": 500 }
      }
    }
  }
}
