{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "urn:sbv:iso20022:auth.018.001.04",
  "title": "CurrencyControlRequestOrLetter — auth.018.001.04 (SBV profile)",
  "description": "ISO 20022 auth.018.001.04: Kiểm soát ngoại hối SBV → NHTM",
  "type": "object",
  "required": ["Document"],
  "properties": {
    "Document": {
      "type": "object",
      "required": ["CcyCtrlReqOrLttr"],
      "properties": {
        "CcyCtrlReqOrLttr": {
          "type": "object",
          "required": ["GrpHdr", "CcyCtrl"],
          "properties": {
            "GrpHdr": {
              "type": "object",
              "required": ["MsgId", "CreDtTm", "NbOfTxs"],
              "properties": {
                "MsgId":   { "type": "string", "maxLength": 35 },
                "CreDtTm": { "type": "string", "format": "date-time" },
                "NbOfTxs": { "type": "string", "pattern": "^[0-9]{1,15}$" }
              }
            },
            "CcyCtrl": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "object",
                "required": ["TxId", "TxDt", "Tp", "RptgCcy"],
                "properties": {
                  "TxId":      { "type": "string", "maxLength": 35 },
                  "TxDt":      { "type": "string", "format": "date" },
                  "Tp":        { "type": "object", "required": ["Cd"], "properties": { "Cd": { "type": "string", "maxLength": 4 } } },
                  "RptgCcy":   { "type": "string", "pattern": "^[A-Z]{3}$" },
                  "RptgAmt": {
                    "type": "object",
                    "properties": {
                      "ActvCcyAndAmt": { "type": "object", "required": ["_","$"], "properties": { "_": { "type": "string" }, "$": { "type": "object", "properties": { "Ccy": { "type": "string" } } } } }
                    }
                  },
                  "OrgnlTx": {
                    "type": "object",
                    "properties": {
                      "OrgnlTxId":  { "type": "string", "maxLength": 35 },
                      "OrgnlUETR":  { "type": "string", "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
