{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://noxdevelopment-studios.github.io/migration-doctor/snapshot.schema.json",
  "title": "Migration Doctor snapshot",
  "description": "Read-only export of Jira Data Center configuration (no issues, no attachments) produced by the migration-doctor-snapshot script and uploaded to the Migration Doctor Forge app. schemaVersion 1.",
  "type": "object",
  "required": ["format", "schemaVersion", "createdAt", "source", "users", "groups", "projects", "fields", "statuses", "filters", "dashboards", "workflows", "permissionSchemes"],
  "additionalProperties": false,
  "properties": {
    "format": { "const": "migration-doctor-snapshot" },
    "schemaVersion": { "const": 1 },
    "createdAt": { "type": "string", "format": "date-time" },
    "coverage": {
      "type": "object",
      "description": "Which sections are complete. Jira DC REST cannot list all filters, dashboard owners or workflow rules; those come from the admin's read-only SQL exports. Values: full, rest-partial, rest-no-owner, none.",
      "additionalProperties": { "enum": ["full", "rest-partial", "rest-no-owner", "none"] }
    },
    "generator": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "version": { "type": "string" }
      }
    },
    "source": {
      "type": "object",
      "required": ["product", "deployment", "version"],
      "properties": {
        "product": { "const": "jira" },
        "deployment": { "enum": ["datacenter", "server"] },
        "version": { "type": "string", "description": "Jira version, e.g. 9.12.3" },
        "baseUrl": { "type": "string" },
        "serverTitle": { "type": "string" }
      }
    },
    "users": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "active"],
        "properties": {
          "key": { "type": "string", "description": "DC user key, e.g. JIRAUSER10100 or the legacy username" },
          "name": { "type": "string", "description": "DC username used in JQL" },
          "displayName": { "type": "string" },
          "email": { "type": ["string", "null"] },
          "active": { "type": "boolean" }
        }
      }
    },
    "groups": {
      "type": "array",
      "items": { "type": "object", "required": ["name"], "properties": { "name": { "type": "string" } } }
    },
    "projects": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "key", "name"],
        "properties": {
          "id": { "type": "string" },
          "key": { "type": "string" },
          "name": { "type": "string" },
          "type": { "type": "string" }
        }
      }
    },
    "fields": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "name", "custom"],
        "properties": {
          "id": { "type": "string", "description": "e.g. summary or customfield_10010" },
          "name": { "type": "string" },
          "custom": { "type": "boolean" },
          "type": { "type": ["string", "null"], "description": "Custom field type key, e.g. com.atlassian.jira.plugin.system.customfieldtypes:select" }
        }
      }
    },
    "statuses": {
      "type": "array",
      "items": { "type": "object", "required": ["id", "name"], "properties": { "id": { "type": "string" }, "name": { "type": "string" } } }
    },
    "filters": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "name", "jql", "owner"],
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "description": { "type": ["string", "null"] },
          "jql": { "type": "string" },
          "owner": { "type": "string", "description": "DC username of the owner" },
          "sharePermissions": { "type": "array", "items": { "$ref": "#/$defs/share" } }
        }
      }
    },
    "dashboards": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "name"],
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "owner": { "type": ["string", "null"] },
          "sharePermissions": { "type": "array", "items": { "$ref": "#/$defs/share" } },
          "gadgets": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "title": { "type": "string" },
                "moduleKey": { "type": "string" },
                "filterId": { "type": ["string", "null"] }
              }
            }
          }
        }
      }
    },
    "workflows": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "transitions"],
        "properties": {
          "name": { "type": "string" },
          "transitions": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["name", "to", "rules"],
              "properties": {
                "id": { "type": "string" },
                "name": { "type": "string" },
                "from": { "type": "array", "items": { "type": "string" }, "description": "Source status names; empty for global or initial transitions" },
                "to": { "type": "string", "description": "Target status name" },
                "rules": { "type": "array", "items": { "$ref": "#/$defs/rule" } }
              }
            }
          }
        }
      }
    },
    "permissionSchemes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "name", "permissions"],
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "projectKeys": { "type": "array", "items": { "type": "string" } },
          "permissions": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["permission", "holder"],
              "properties": {
                "permission": { "type": "string" },
                "holder": {
                  "type": "object",
                  "required": ["type"],
                  "properties": {
                    "type": { "type": "string", "description": "group, projectRole, user, applicationRole, anyone, reporter, assignee, projectLead, userCustomField, groupCustomField" },
                    "parameter": { "type": ["string", "null"] }
                  }
                }
              }
            }
          }
        }
      }
    },
    "boards": {
      "type": "array",
      "description": "Optional in schemaVersion 1 (used by v1 checks)",
      "items": {
        "type": "object",
        "required": ["id", "name"],
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "type": { "type": "string" },
          "filterId": { "type": ["string", "null"] }
        }
      }
    }
  },
  "$defs": {
    "share": {
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": { "enum": ["global", "loggedin", "authenticated", "group", "project", "projectRole", "user"] },
        "group": { "type": "string" },
        "projectKey": { "type": "string" },
        "role": { "type": "string" },
        "user": { "type": "string" }
      }
    },
    "rule": {
      "type": "object",
      "required": ["kind", "type"],
      "properties": {
        "kind": { "enum": ["condition", "validator", "postFunction"] },
        "type": { "type": "string", "description": "Implementation class or module key" },
        "pluginKey": { "type": ["string", "null"], "description": "App providing the rule; null or com.atlassian.jira for built-in" },
        "summary": { "type": "string", "description": "Short human description, if known" }
      }
    }
  }
}
