{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "urn:sbv:iso20022:pain.008.001.09",
  "title": "CustomerDirectDebitInitiation — pain.008.001.09 (SBV profile)",
  "description": "ISO 20022 pain.008.001.09: Khởi tạo ghi nợ trực tiếp",
  "type": "object",
  "required": ["Document"],
  "properties": {
    "Document": {
      "type": "object",
      "required": ["CstmrDrctDbtInitn"],
      "properties": {
        "CstmrDrctDbtInitn": {
          "type": "object",
          "required": ["GrpHdr", "PmtInf"],
          "properties": {
            "GrpHdr": {
              "type": "object",
              "required": ["MsgId", "CreDtTm", "NbOfTxs", "CtrlSum", "InitgPty"],
              "properties": {
                "MsgId":    { "type": "string", "maxLength": 35 },
                "CreDtTm":  { "type": "string", "format": "date-time" },
                "NbOfTxs":  { "type": "string", "pattern": "^[0-9]{1,15}$" },
                "CtrlSum":  { "type": "number", "minimum": 0 },
                "InitgPty": { "type": "object", "properties": { "Nm": { "type": "string", "maxLength": 140 } } }
              }
            },
            "PmtInf": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "object",
                "required": ["PmtInfId", "PmtMtd", "NbOfTxs", "CtrlSum", "PmtTpInf", "ReqdColltnDt", "Cdtr", "CdtrAcct", "CdtrAgt"],
                "properties": {
                  "PmtInfId":      { "type": "string", "maxLength": 35 },
                  "PmtMtd":        { "type": "string", "enum": ["DD"] },
                  "NbOfTxs":       { "type": "string" },
                  "CtrlSum":       { "type": "number", "minimum": 0 },
                  "ReqdColltnDt":  { "type": "string", "format": "date" },
                  "Cdtr":          { "type": "object", "required": ["Nm"], "properties": { "Nm": { "type": "string", "maxLength": 140 } } },
                  "CdtrAcct":      { "type": "object", "required": ["Id"], "properties": { "Id": { "type": "object" } } },
                  "CdtrAgt":       { "type": "object", "required": ["FinInstnId"], "properties": { "FinInstnId": { "type": "object", "properties": { "BICFI": { "type": "string" } } } } },
                  "DrctDbtTxInf": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "required": ["PmtId", "InstdAmt", "DbtrAgt", "Dbtr", "DbtrAcct"],
                      "properties": {
                        "PmtId":   { "type": "object", "required": ["EndToEndId"], "properties": { "EndToEndId": { "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}$" } } },
                        "InstdAmt": { "type": "object", "required": ["_", "$"], "properties": { "_": { "type": "string" }, "$": { "type": "object", "properties": { "Ccy": { "type": "string", "pattern": "^[A-Z]{3}$" } } } } },
                        "DbtrAgt":  { "type": "object", "required": ["FinInstnId"], "properties": { "FinInstnId": { "type": "object" } } },
                        "Dbtr":     { "type": "object", "required": ["Nm"], "properties": { "Nm": { "type": "string", "maxLength": 140 } } },
                        "DbtrAcct": { "type": "object", "required": ["Id"], "properties": { "Id": { "type": "object" } } }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
