{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aka.ms/sslz/schemas/container-apps-cool-profile-manifest.schema.json",
  "title": "SSLZ execution-disabled Container Apps cool profile manifest",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "manifestVersion",
    "generatedBy",
    "manifestDigest",
    "provider",
    "mode",
    "environment",
    "source",
    "target",
    "artifacts",
    "stateIsolation",
    "steps",
    "resume",
    "postchecks",
    "rollback",
    "teardown",
    "safety"
  ],
  "properties": {
    "schemaVersion": {
      "const": "1.0.0"
    },
    "manifestVersion": {
      "const": "1.0.0"
    },
    "generatedBy": {
      "const": "startup-container-apps-cool-plan.mjs"
    },
    "manifestDigest": {
      "$ref": "#/$defs/digest"
    },
    "provider": {
      "enum": ["bicep", "terraform"]
    },
    "mode": {
      "const": "cool-container-apps"
    },
    "environment": {
      "const": "nonprod"
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["foundationPlanId", "foundationPlanDigest", "readinessEvidenceDigest", "profileDecisionDigest"],
      "properties": {
        "foundationPlanId": {
          "$ref": "#/$defs/id"
        },
        "foundationPlanDigest": {
          "$ref": "#/$defs/digest"
        },
        "readinessEvidenceDigest": {
          "$ref": "#/$defs/digest"
        },
        "profileDecisionDigest": {
          "$ref": "#/$defs/digest"
        }
      }
    },
    "target": {
      "type": "object",
      "additionalProperties": false,
      "required": ["subscriptionId", "region", "scope", "primaryScope", "primaryVnetCidr", "secondaryVnetCidr", "resourceNames"],
      "properties": {
        "subscriptionId": {
          "$ref": "#/$defs/uuid"
        },
        "region": {
          "$ref": "#/$defs/region"
        },
        "scope": {
          "$ref": "#/$defs/resourceId"
        },
        "primaryScope": {
          "$ref": "#/$defs/resourceId"
        },
        "primaryVnetCidr": {
          "$ref": "#/$defs/cidr"
        },
        "secondaryVnetCidr": {
          "$ref": "#/$defs/cidr"
        },
        "resourceNames": {
          "type": "object",
          "additionalProperties": false,
          "required": ["resourceGroup", "managedEnvironment", "containerApp", "managedIdentity"],
          "properties": {
            "resourceGroup": {
              "$ref": "#/$defs/name"
            },
            "managedEnvironment": {
              "$ref": "#/$defs/name"
            },
            "containerApp": {
              "$ref": "#/$defs/name"
            },
            "managedIdentity": {
              "$ref": "#/$defs/name"
            }
          }
        }
      }
    },
    "artifacts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["parameterPath", "parameterDigest", "decisionDigest", "sourcePath", "sourceDigest"],
      "properties": {
        "parameterPath": {
          "$ref": "#/$defs/generatedPath"
        },
        "parameterDigest": {
          "$ref": "#/$defs/digest"
        },
        "decisionDigest": {
          "$ref": "#/$defs/digest"
        },
        "sourcePath": {
          "enum": [
            "infra/bicep/cool-container-apps.bicep",
            "infra/terraform/cool-container-apps"
          ]
        },
        "sourceDigest": {
          "$ref": "#/$defs/digest"
        }
      }
    },
    "stateIsolation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "identifier", "primaryIdentifier", "foundationIdentifier", "isolated"],
      "properties": {
        "kind": {
          "enum": ["arm-deployment-history", "terraform-remote-state"]
        },
        "identifier": {
          "type": "string",
          "minLength": 3
        },
        "primaryIdentifier": {
          "type": "string",
          "minLength": 3
        },
        "foundationIdentifier": {
          "type": "string",
          "minLength": 3
        },
        "isolated": {
          "const": true
        }
      }
    },
    "steps": {
      "type": "array",
      "minItems": 10,
      "items": {
        "$ref": "#/$defs/step"
      }
    },
    "resume": {
      "$ref": "#/$defs/resume"
    },
    "postchecks": {
      "type": "array",
      "minItems": 8,
      "items": {
        "$ref": "#/$defs/postcheck"
      }
    },
    "rollback": {
      "type": "object",
      "additionalProperties": false,
      "required": ["intent", "approvalRequired", "status", "orderedActions"],
      "properties": {
        "intent": {
          "const": "review-only"
        },
        "approvalRequired": {
          "const": true
        },
        "status": {
          "const": "not-run"
        },
        "orderedActions": {
          "type": "array",
          "minItems": 4,
          "items": {
            "type": "string",
            "minLength": 3
          }
        }
      }
    },
    "teardown": {
      "type": "object",
      "additionalProperties": false,
      "required": ["intent", "approvalRequired", "status", "triggers", "orderedActions"],
      "properties": {
        "intent": {
          "const": "review-only"
        },
        "approvalRequired": {
          "const": true
        },
        "status": {
          "const": "not-run"
        },
        "triggers": {
          "type": "array",
          "minItems": 3,
          "items": {
            "type": "string",
            "minLength": 3
          }
        },
        "orderedActions": {
          "type": "array",
          "minItems": 4,
          "items": {
            "type": "string",
            "minLength": 3
          }
        }
      }
    },
    "safety": {
      "$ref": "#/$defs/safety"
    }
  },
  "$defs": {
    "digest": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "uuid": {
      "type": "string",
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "name": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]{2,89}$"
    },
    "region": {
      "type": "string",
      "pattern": "^[a-z0-9]+$"
    },
    "cidr": {
      "type": "string",
      "pattern": "^\\d{1,3}(?:\\.\\d{1,3}){3}/\\d{1,2}$"
    },
    "resourceId": {
      "type": "string",
      "pattern": "^/subscriptions/[0-9a-f-]+/resourceGroups/[A-Za-z0-9._()-]+/providers/[A-Za-z0-9.]+/[A-Za-z0-9._()/-]+$"
    },
    "generatedPath": {
      "type": "string",
      "pattern": "^\\.sslz/generated/[A-Za-z0-9._/-]+$"
    },
    "step": {
      "type": "object",
      "additionalProperties": false,
      "required": ["order", "id", "intent", "state", "attempt", "maxAttempts", "retryable", "idempotencyKey", "postcheckIds"],
      "properties": {
        "order": {
          "type": "integer",
          "minimum": 1
        },
        "id": {
          "type": "string",
          "pattern": "^cool\\.container-apps\\.[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "intent": {
          "type": "string",
          "minLength": 3
        },
        "state": {
          "enum": ["pending", "running", "succeeded", "failed", "cleanup-required"]
        },
        "attempt": {
          "type": "integer",
          "minimum": 0
        },
        "maxAttempts": {
          "type": "integer",
          "minimum": 1
        },
        "retryable": {
          "type": "boolean"
        },
        "idempotencyKey": {
          "$ref": "#/$defs/digest"
        },
        "postcheckIds": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^cool\\.container-apps\\.postcheck\\.[a-z0-9]+(?:-[a-z0-9]+)*$"
          }
        }
      }
    },
    "resume": {
      "type": "object",
      "additionalProperties": false,
      "required": ["allowed", "action", "stepId", "reason"],
      "properties": {
        "allowed": {
          "type": "boolean"
        },
        "action": {
          "enum": ["start", "resume", "retry", "reconcile", "cleanup", "complete"]
        },
        "stepId": {
          "type": ["string", "null"]
        },
        "reason": {
          "type": "string",
          "minLength": 3
        }
      }
    },
    "postcheck": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "status", "readOnly", "blocking", "description"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^cool\\.container-apps\\.postcheck\\.[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "status": {
          "enum": ["not-run", "pass", "fail"]
        },
        "readOnly": {
          "const": true
        },
        "blocking": {
          "const": true
        },
        "description": {
          "type": "string",
          "minLength": 3
        }
      }
    },
    "safety": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "executionEnabled",
        "azureOperations",
        "providerRegistration",
        "productionExecution",
        "globalIngress",
        "dnsCutover",
        "dataReplication",
        "dataFailover",
        "endToEndRecoveryClaim"
      ],
      "properties": {
        "executionEnabled": {
          "const": false
        },
        "azureOperations": {
          "const": "none"
        },
        "providerRegistration": {
          "const": false
        },
        "productionExecution": {
          "const": false
        },
        "globalIngress": {
          "const": false
        },
        "dnsCutover": {
          "const": false
        },
        "dataReplication": {
          "const": false
        },
        "dataFailover": {
          "const": false
        },
        "endToEndRecoveryClaim": {
          "const": false
        }
      }
    }
  }
}
