{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "urn:sbv:iso20022:head.001.001.03",
  "title": "BusinessApplicationHeader — head.001.001.03 (SBV profile)",
  "description": "ISO 20022 head.001.001.03: Business Application Header bao ngoài mọi message",
  "type": "object",
  "required": ["AppHdr"],
  "properties": {
    "AppHdr": {
      "type": "object",
      "required": ["Fr", "To", "BizMsgIdr", "MsgDefIdr", "CreDt"],
      "properties": {

        "Fr": {
          "type": "object",
          "required": ["FIId"],
          "properties": {
            "FIId": {
              "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", "pattern": "^[A-Z0-9]{18}[0-9]{2}$" }
                  }
                }
              }
            }
          }
        },

        "To": {
          "type": "object",
          "required": ["FIId"],
          "properties": {
            "FIId": {
              "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", "pattern": "^[A-Z0-9]{18}[0-9]{2}$" }
                  }
                }
              }
            }
          }
        },

        "BizMsgIdr": { "type": "string", "maxLength": 35, "description": "Business Message Identifier — unique per message" },
        "MsgDefIdr":  { "type": "string", "maxLength": 35, "description": "Message Definition Identifier (vd: pacs.008.001.09)" },
        "BizSvc":     { "type": "string", "maxLength": 35, "description": "Business Service (tuỳ chọn)" },
        "CreDt":      { "type": "string", "format": "date-time", "description": "Thời gian tạo message (UTC+7)" },
        "CpyDplct":   { "type": "string", "enum": ["COPY","DUPL"], "description": "Bản sao / Trùng lặp (nếu có)" },

        "Sgntr": {
          "type": "object",
          "description": "JWS hoặc XML-DSig signature block",
          "properties": {
            "SignedInfo":      { "type": "object" },
            "SignatureValue":  { "type": "string" },
            "KeyInfo":         { "type": "object" }
          }
        }

      }
    }
  }
}
