{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/alfil-co/json-schema/alfil-co-contrato-schema.json",
  "title": "Contrato",
  "description": "Detalle de contrato SECOP (sin datos de contacto semiprivados)",
  "x-generated": "2026-11-01",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/alfil-co-openapi.json#/components/schemas/Contrato",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "objeto": {
      "type": "string"
    },
    "entidad": {
      "type": "object",
      "properties": {
        "nombre": {
          "type": "string"
        },
        "nit": {
          "type": "string"
        }
      },
      "required": [
        "nombre",
        "nit"
      ],
      "additionalProperties": false
    },
    "contratista": {
      "type": "object",
      "properties": {
        "nombre": {
          "type": "string"
        },
        "tipo": {
          "type": "string",
          "enum": [
            "persona_juridica",
            "persona_natural"
          ]
        },
        "identifier": {
          "anyOf": [
            {
              "$ref": "#/$defs/Identifier"
            },
            {
              "type": "null"
            }
          ],
          "description": "Cédula/NIT completo — solo en detalle (ADR-020)"
        }
      },
      "required": [
        "nombre",
        "tipo",
        "identifier"
      ],
      "additionalProperties": false
    },
    "valor_cop": {
      "type": "string"
    },
    "valor_dudoso": {
      "type": "boolean",
      "description": "true cuando el valor publicado no pasa la regla de plausibilidad de Alfil y ninguna fuente lo confirmó como está"
    },
    "veredicto_valor": {
      "type": "string",
      "enum": [
        "plausible",
        "recovered",
        "document_verified",
        "unverifiable"
      ],
      "description": "Veredicto de Alfil sobre el valor publicado: plausible, recuperado de las fuentes de financiación, verificado en el contrato firmado o sin verificar"
    },
    "valor_corregido": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "description": "Valor en COP que confirman las fuentes de financiación o el contrato firmado; null cuando no hay corrección"
    },
    "fecha_firma": {
      "type": "string"
    },
    "fuente": {
      "$ref": "#/$defs/Fuente"
    },
    "referencias": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Referencia"
      }
    }
  },
  "required": [
    "id",
    "objeto",
    "entidad",
    "contratista",
    "valor_cop",
    "valor_dudoso",
    "veredicto_valor",
    "valor_corregido",
    "fuente",
    "referencias"
  ],
  "additionalProperties": false,
  "$defs": {
    "Fuente": {
      "type": "object",
      "properties": {
        "nombre": {
          "type": "string",
          "description": "Fuente oficial del dato"
        },
        "url": {
          "description": "URL de la fuente oficial",
          "type": "string"
        },
        "corte": {
          "type": "string",
          "description": "Fecha de corte del dato (ISO 8601)"
        },
        "licencia": {
          "description": "Licencia de la fuente",
          "type": "string"
        }
      },
      "required": [
        "nombre",
        "corte"
      ],
      "additionalProperties": false,
      "description": "Proveniencia: fuente oficial y fecha de corte (atribución Ley 1712)"
    },
    "Identifier": {
      "type": "object",
      "properties": {
        "scheme": {
          "type": "string",
          "enum": [
            "COL-NIT",
            "COL-IDCARD"
          ],
          "description": "Esquema del identificador (OCDS)"
        },
        "id": {
          "type": "string",
          "description": "Número de identificación"
        }
      },
      "required": [
        "scheme",
        "id"
      ],
      "additionalProperties": false,
      "description": "Identificador de persona o entidad (estándar OCDS)"
    },
    "Referencia": {
      "type": "object",
      "properties": {
        "tipo": {
          "type": "string",
          "enum": [
            "pagina_alfil",
            "registro_oficial",
            "documento_oficial",
            "coleccion_oficial"
          ]
        },
        "titulo": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "pattern": "^[hH][tT][tT][pP][sS]:\\/\\/[^/?#@]+(?:[/?#].*)?$",
          "format": "uri"
        },
        "proveedor": {
          "type": "string"
        },
        "id_externo": {
          "type": "string"
        }
      },
      "required": [
        "tipo",
        "titulo",
        "url",
        "proveedor"
      ],
      "additionalProperties": false,
      "description": "Enlace HTTPS navegable a Alfil o a una fuente oficial"
    }
  }
}