{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mandateshield.com/schemas/provider-submission-v1.json",
  "title": "MandateShield ProviderSubmission v1",
  "description": "Canonical state record for one provider request bound to one claimed MandateShield execution permit. The record is a durable orchestration ledger; its state alone is not settlement evidence.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "permit_id",
    "authorization_id",
    "provider_audience",
    "provider_profile",
    "provider_environment",
    "provider_account",
    "provider_request_id",
    "provider_request_digest",
    "provider_idempotency_key",
    "state",
    "claim_id",
    "payment_reference",
    "caller_outcome",
    "prepared_at",
    "submitting_at",
    "acknowledged_at",
    "terminal_at",
    "updated_at"
  ],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^psub_[a-f0-9]{32}$"
    },
    "permit_id": {
      "type": "string",
      "pattern": "^msp_[a-f0-9]{32}$"
    },
    "authorization_id": {
      "type": "string",
      "pattern": "^exec_auth_[a-f0-9]{32}$"
    },
    "provider_audience": {
      "type": "string",
      "minLength": 1,
      "maxLength": 240
    },
    "provider_profile": {
      "type": "string",
      "enum": [
        "GENERIC_HTTP_V1",
        "STRIPE_PAYMENT_INTENTS_V1",
        "X402_V2_EXACT",
        "MPP_CHARGE_V1"
      ]
    },
    "provider_environment": {
      "type": "string",
      "enum": [
        "test",
        "live"
      ]
    },
    "provider_account": {
      "type": "string",
      "minLength": 1,
      "maxLength": 240
    },
    "provider_request_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 240
    },
    "provider_request_digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "provider_idempotency_key": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._:~-]{1,256}$"
    },
    "state": {
      "type": "string",
      "enum": [
        "PREPARED",
        "SUBMITTING",
        "ACKNOWLEDGED",
        "UNKNOWN",
        "FAILED_CONFIRMED",
        "SETTLED",
        "CONFLICT"
      ]
    },
    "claim_id": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^mspc_[a-f0-9]{32}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "payment_reference": {
      "anyOf": [
        {
          "type": "string",
          "minLength": 1,
          "maxLength": 240
        },
        {
          "type": "null"
        }
      ]
    },
    "caller_outcome": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "COMMITTED",
        "FAILED",
        "PENDING",
        "UNKNOWN",
        null
      ],
      "description": "Authenticated caller observation only; it is not independently verified evidence."
    },
    "prepared_at": {
      "type": "integer",
      "minimum": 1,
      "description": "Unix milliseconds."
    },
    "submitting_at": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1,
      "description": "Unix milliseconds when present."
    },
    "acknowledged_at": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1,
      "description": "Unix milliseconds when present."
    },
    "terminal_at": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1,
      "description": "Unix milliseconds when present."
    },
    "updated_at": {
      "type": "integer",
      "minimum": 1,
      "description": "Unix milliseconds."
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "state": {
            "const": "PREPARED"
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "properties": {
          "claim_id": {
            "type": "null"
          },
          "submitting_at": {
            "type": "null"
          },
          "terminal_at": {
            "type": "null"
          }
        }
      },
      "else": {
        "properties": {
          "claim_id": {
            "type": "string",
            "pattern": "^mspc_[a-f0-9]{32}$"
          },
          "submitting_at": {
            "type": "integer",
            "minimum": 1
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "state": {
            "enum": [
              "FAILED_CONFIRMED",
              "SETTLED",
              "CONFLICT"
            ]
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "properties": {
          "terminal_at": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "else": {
        "properties": {
          "terminal_at": {
            "type": "null"
          }
        }
      }
    }
  ]
}
