{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://validatapp.com/docs/schemas/channel.validation.v1.schema.json",
  "title": "channel.validation.v1",
  "description": "Solicitud de validación COD. Contrato cerrado: no se aceptan campos desconocidos ni claves de identidad, política o datos personales innecesarios (ver docs).",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "channel",
    "external_order_ref",
    "buyer",
    "delivery",
    "order",
    "event_at"
  ],
  "properties": {
    "schema_version": {
      "const": "channel.validation.v1"
    },
    "channel": {
      "enum": [
        "whatsapp",
        "woocommerce"
      ]
    },
    "external_order_ref": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
      "minLength": 1,
      "maxLength": 128
    },
    "buyer": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "phone"
      ],
      "properties": {
        "phone": {
          "type": "string",
          "pattern": "^[0-9+()\\s.-]{7,32}$",
          "minLength": 7,
          "maxLength": 32
        }
      }
    },
    "delivery": {
      "oneOf": [
        {
          "title": "HOME_DELIVERY",
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode",
            "country",
            "department",
            "city",
            "address_line"
          ],
          "properties": {
            "mode": {
              "const": "HOME_DELIVERY"
            },
            "country": {
              "type": "string",
              "pattern": "^[A-Z]{2}$"
            },
            "department": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            },
            "city": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            },
            "address_line": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "complement": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            }
          }
        },
        {
          "title": "OFFICE_PICKUP",
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode",
            "country",
            "office_ref"
          ],
          "properties": {
            "mode": {
              "const": "OFFICE_PICKUP"
            },
            "country": {
              "type": "string",
              "pattern": "^[A-Z]{2}$"
            },
            "office_ref": {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
              "minLength": 1,
              "maxLength": 128
            }
          }
        }
      ]
    },
    "order": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "total",
        "currency",
        "payment_intent"
      ],
      "properties": {
        "total": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,11})(?:\\.[0-9]{1,4})?$",
          "maxLength": 17
        },
        "currency": {
          "enum": [
            "ARS",
            "AUD",
            "BRL",
            "CAD",
            "CHF",
            "CLP",
            "COP",
            "EUR",
            "GBP",
            "JPY",
            "MXN",
            "PEN",
            "USD"
          ]
        },
        "payment_intent": {
          "enum": [
            "cod",
            "prepaid",
            "partial"
          ]
        },
        "items": {
          "type": "array",
          "maxItems": 50,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "sku_ref",
              "quantity"
            ],
            "properties": {
              "sku_ref": {
                "type": "string",
                "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
                "minLength": 1,
                "maxLength": 128
              },
              "quantity": {
                "type": "integer",
                "minimum": 1,
                "maximum": 999
              }
            }
          }
        }
      }
    },
    "event_at": {
      "type": "string",
      "pattern": "^[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])T(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]{1,6})?Z$",
      "maxLength": 27
    },
    "trace": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "conversation_ref": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
          "minLength": 1,
          "maxLength": 128
        }
      }
    }
  }
}
