{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "Secret.schema.json",
  "title": "Secret.schema.json",
  "description": "A declared sensitive-value or provider-key requirement. Runtime configuration supplies its location or identifier through security.secrets.<name>.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "name",
    "purpose",
    "type",
    "ttl"
  ],
  "properties": {
    "name": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]+$",
      "description": "Resource name, unique among Secret resources in this System. Used exactly in filenames and references."
    },
    "type": {
      "enum": [
        "stored-value",
        "object",
        "encryption-key",
        "signing-key",
        "tls-private-key",
        "certificate",
        "provider-token"
      ]
    },
    "schema": {
      "type": "object",
      "additionalProperties": true,
      "description": "JSON schema describing an object Secret's expected properties without credentials or example values."
    },
    "purpose": {
      "type": "string",
      "minLength": 1,
      "description": "Why the Secret is needed, its permitted perimeter, and how named Services or Process code use it. Explain the requested lifetime for security review."
    },
    "required": {
      "type": "boolean",
      "default": true
    },
    "ttl": {
      "type": "integer",
      "minimum": 0,
      "description": "Requested maximum lifetime in seconds, subject to security approval and provider policy. Zero requests no automatic expiry and requires expiryReason."
    },
    "expiryReason": {
      "type": "string",
      "minLength": 1,
      "description": "Why no automatic expiry is needed and how use is bounded and rotation or revocation will be handled."
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "const": "object"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "required": [
          "schema"
        ],
        "properties": {
          "schema": {
            "required": [
              "type",
              "properties"
            ],
            "properties": {
              "type": {
                "const": "object"
              },
              "properties": {
                "type": "object"
              }
            }
          }
        }
      },
      "else": {
        "not": {
          "required": [
            "schema"
          ]
        }
      }
    },
    {
      "if": {
        "properties": {
          "ttl": {
            "const": 0
          }
        },
        "required": [
          "ttl"
        ]
      },
      "then": {
        "required": [
          "expiryReason"
        ]
      }
    }
  ]
}
