{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "urn:sbv:iso20022:pain.001.001.09",
  "title": "CustomerCreditTransferInitiation — pain.001.001.09 (SBV profile)",
  "description": "ISO 20022 pain.001.001.09 adapted for SBV domestic + mBridge usage",
  "type": "object",
  "required": ["Document"],
  "properties": {
    "Document": {
      "type": "object",
      "required": ["CstmrCdtTrfInitn"],
      "properties": {
        "CstmrCdtTrfInitn": {
          "type": "object",
          "required": ["GrpHdr", "PmtInf"],
          "properties": {

            "GrpHdr": {
              "type": "object",
              "required": ["MsgId", "CreDtTm", "NbOfTxs", "CtrlSum", "InitgPty"],
              "properties": {
                "MsgId":     { "type": "string", "maxLength": 35, "description": "Message ID — duy nhất toàn hệ thống SBV" },
                "CreDtTm":   { "type": "string", "format": "date-time", "description": "ISO 8601 UTC+7 creation timestamp" },
                "NbOfTxs":   { "type": "string", "pattern": "^[0-9]{1,15}$" },
                "CtrlSum":   { "type": "number", "minimum": 0, "description": "Tổng số tiền kiểm soát (VND)" },
                "InitgPty":  {
                  "type": "object",
                  "required": ["Nm", "Id"],
                  "properties": {
                    "Nm": { "type": "string", "maxLength": 140 },
                    "Id": {
                      "type": "object",
                      "properties": {
                        "OrgId": {
                          "type": "object",
                          "properties": {
                            "LEI": { "type": "string", "pattern": "^[A-Z0-9]{18}[0-9]{2}$", "description": "Legal Entity Identifier 20 ký tự" },
                            "Othr": {
                              "type": "object",
                              "properties": {
                                "Id":    { "type": "string", "maxLength": 35, "description": "Mã tổ chức tín dụng SBV cấp" },
                                "SchmeNm": { "type": "object", "properties": { "Cd": { "type": "string", "enum": ["BANK", "CUST", "DUNS"] } } }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            },

            "PmtInf": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "object",
                "required": ["PmtInfId", "PmtMtd", "NbOfTxs", "CtrlSum", "PmtTpInf", "ReqdExctnDt", "Dbtr", "DbtrAcct", "DbtrAgt", "CdtTrfTxInf"],
                "properties": {
                  "PmtInfId":     { "type": "string", "maxLength": 35 },
                  "PmtMtd":       { "type": "string", "enum": ["TRF", "TRA"] },
                  "NbOfTxs":      { "type": "string", "pattern": "^[0-9]{1,15}$" },
                  "CtrlSum":      { "type": "number", "minimum": 0 },
                  "PmtTpInf": {
                    "type": "object",
                    "properties": {
                      "SvcLvl":  { "type": "object", "properties": { "Cd": { "type": "string", "enum": ["SEPA","NURG","URGP","SDVA"] } } },
                      "LclInstrm": { "type": "object", "properties": { "Prtry": { "type": "string", "enum": ["IBPS","MBRIDGE","VNLH"] } } },
                      "CtgyPurp": { "type": "object", "properties": { "Cd": { "type": "string", "maxLength": 4, "description": "SALA TAXS GOVT PENS SSBE..." } } }
                    }
                  },
                  "ReqdExctnDt":  { "type": "object", "properties": { "Dt": { "type": "string", "format": "date" } } },
                  "Dbtr": {
                    "type": "object",
                    "required": ["Nm"],
                    "properties": {
                      "Nm":   { "type": "string", "maxLength": 140 },
                      "PstlAdr": { "type": "object", "properties": { "Ctry": { "type": "string", "pattern": "^[A-Z]{2}$" } } }
                    }
                  },
                  "DbtrAcct": { "type": "object", "required": ["Id"], "properties": { "Id": { "type": "object", "properties": { "IBAN": { "type": "string" }, "Othr": { "type": "object", "properties": { "Id": { "type": "string", "maxLength": 34, "description": "Số tài khoản nội địa" } } } } } } },
                  "DbtrAgt":  { "type": "object", "required": ["FinInstnId"], "properties": { "FinInstnId": { "type": "object", "properties": { "BICFI": { "type": "string", "pattern": "^[A-Z]{6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3})?$" }, "LEI": { "type": "string" } } } } },
                  "CdtTrfTxInf": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "required": ["PmtId", "Amt", "CdtrAgt", "Cdtr", "CdtrAcct"],
                      "properties": {
                        "PmtId":    { "type": "object", "required": ["EndToEndId"], "properties": { "EndToEndId": { "type": "string", "maxLength": 35 }, "TxId": { "type": "string", "maxLength": 35 }, "UETR": { "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}$", "description": "Unique End-to-end Transaction Reference (UUID v4)" } } },
                        "Amt":      { "type": "object", "properties": { "InstdAmt": { "type": "object", "required": ["value","Ccy"], "properties": { "value": { "type": "number", "minimum": 0.01 }, "Ccy": { "type": "string", "pattern": "^[A-Z]{3}$", "description": "VND hoặc ngoại tệ" } } } } },
                        "Purp":     { "type": "object", "properties": { "Cd": { "type": "string", "maxLength": 4 } } },
                        "RmtInf":   { "type": "object", "properties": { "Ustrd": { "type": "array", "items": { "type": "string", "maxLength": 140 }, "maxItems": 4 } } },
                        "CdtrAgt":  { "type": "object", "required": ["FinInstnId"], "properties": { "FinInstnId": { "type": "object", "properties": { "BICFI": { "type": "string" }, "LEI": { "type": "string" } } } } },
                        "Cdtr":     { "type": "object", "required": ["Nm"], "properties": { "Nm": { "type": "string", "maxLength": 140 } } },
                        "CdtrAcct": { "type": "object", "required": ["Id"], "properties": { "Id": { "type": "object", "properties": { "Othr": { "type": "object", "properties": { "Id": { "type": "string", "maxLength": 34 } } } } } } }
                      }
                    }
                  }
                }
              }
            }

          }
        }
      }
    }
  }
}
