{
  "id": "dedicated-backup-settings",
  "name": "Validate and restore Dedicated backup settings",
  "risk": "mutating",
  "start": { "path": "/tidbs/{{dedicatedClusterId}}/backup" },
  "goal": [
    "Validate Dedicated Auto Backup and finish with it enabled. The runtime selects one verified phase at a time."
  ],
  "phases": [
    {
      "goal": [
        "Open Backup Setting for {{clusterName}}. Wait for the settings to load and the Auto Backup switch to become operable. Do not change any setting in this phase."
      ],
      "evidence": [{ "kind": "testIdChecked", "testId": "auto-backup", "enabled": true }]
    },
    {
      "skipIf": [{ "kind": "testIdChecked", "testId": "auto-backup", "checked": false, "enabled": true }],
      "goal": [
        "Turn Auto Backup OFF once, then click Save once and wait for Backup Setting to close. If the draft is already OFF, save it without changing the switch again. This phase ends after the OFF save; do not reopen the dialog or turn it back on yet."
      ],
      "evidence": [
        {
          "kind": "acceptedRequest",
          "guardId": "dedicated-backup-settings",
          "bodyEquals": { "snapshot_backup_schedule.disable": true }
        },
        { "kind": "roleAbsent", "role": "dialog", "name": "Backup Setting" }
      ]
    },
    {
      "goal": [
        "Open Backup Setting if it is closed and wait for its data to load. Turn Auto Backup ON once, then click Save once and wait for the dialog to close. If the draft is already ON, save it without toggling again. Keep Auto Backup ON; never restart an OFF cycle."
      ],
      "evidence": [
        {
          "kind": "acceptedRequest",
          "guardId": "dedicated-backup-settings",
          "bodyEquals": { "snapshot_backup_schedule.disable": false }
        },
        { "kind": "roleAbsent", "role": "dialog", "name": "Backup Setting" }
      ]
    }
  ],
  "success": {
    "evidence": [
      { "kind": "url", "matches": "/(?:tidbs|clusters)/[^/]+/backup(?:[/?]|$)" },
      { "kind": "roleAbsent", "role": "dialog", "name": "Backup Setting" }
    ]
  },
  "limits": { "maxDurationMs": 300000, "maxActions": 24 },
  "safety": {
    "deny": [
      "Do not change retention, schedule, or any setting except Auto Backup. Save once when repairing an initially disabled state, or exactly twice when testing and restoring an initially enabled state."
    ],
    "networkGuards": [
      {
        "id": "dedicated-backup-settings",
        "method": "POST",
        "pathMatches": "^/api/v(?:1|2)/orgs/[^/]+/projects/[^/]+/clusters/{{dedicatedClusterId}}/backups/setting$",
        "resourceIdentity": {
          "requestPathMatches": "^/api/v(?:1|2)/orgs/[^/]+/projects/[^/]+/clusters/([^/]+)/backups/setting$",
          "capturedVariable": "dedicatedClusterId"
        },
        "bodyMatches": { "snapshot_backup_schedule.disable": "^(?:true|false)$" },
        "finalRequestBodyEquals": { "snapshot_backup_schedule.disable": false },
        "deduplicateBy": ["snapshot_backup_schedule.disable"],
        "minRequests": 1,
        "maxRequests": 2,
        "required": true
      }
    ]
  }
}
