# StatusPage API Quick Reference

Quick reference for all available `StatusPageAPI` methods.

## Status Pages

```swift
// Fetch all status pages (v1 - requires ScopeStatusPagesRead)
let pages = try await StatusPageAPI.shared.fetchStatusPages()

// Fetch single status page (v1 - requires ScopeStatusPagesRead)
let page = try await StatusPageAPI.shared.fetchStatusPage(id: "page-id")

// Create status page
let newPage = try await StatusPageAPI.shared.createStatusPage(
    name: "My Status Page",
    slug: "my-status-page"
)

// Update status page settings
let updated = try await StatusPageAPI.shared.updateStatusPageSettings(
    pageId: "page-id",
    title: "New Title",
    description: "New description"
)

// Delete status page (requires team context)
try await StatusPageAPI.shared.deleteStatusPage(id: "page-id")
```

## Monitors

```swift
// Fetch all monitors (v1 - requires ScopeMonitorsRead)
let monitors = try await StatusPageAPI.shared.fetchMonitors()

// Fetch single monitor (v1 - requires ScopeMonitorsRead)
let monitor = try await StatusPageAPI.shared.fetchMonitor(id: "monitor-id")

// Fetch monitor availability (v1 - requires ScopeAnalyticsRead)
let availability = try await StatusPageAPI.shared.fetchMonitorAvailability(id: "monitor-id")

// Fetch monitor results
let results = try await StatusPageAPI.shared.fetchMonitorResults(id: "monitor-id")

// Trigger manual check
try await StatusPageAPI.shared.triggerMonitorCheck(id: "monitor-id")

// Pause monitor
try await StatusPageAPI.shared.pauseMonitor(id: "monitor-id")

// Resume monitor
try await StatusPageAPI.shared.resumeMonitor(id: "monitor-id")

// Delete monitor
try await StatusPageAPI.shared.deleteMonitor(id: "monitor-id")
```

## Incidents

```swift
// Fetch all incidents (v1 - requires ScopeIncidentsRead)
let incidents = try await StatusPageAPI.shared.fetchIncidents()

// Fetch single incident (v1 - requires ScopeIncidentsRead)
let incident = try await StatusPageAPI.shared.fetchIncident(id: "incident-id")

// Create incident (v1 - requires ScopeIncidentsWrite)
let newIncident = try await StatusPageAPI.shared.createIncident(
    title: "Database connectivity issues",
    message: "Users may experience slow response times",
    affectedMonitors: ["monitor-1", "monitor-2"]
)

// Update incident (v1 - requires ScopeIncidentsWrite)
let updated = try await StatusPageAPI.shared.updateIncident(
    id: "incident-id",
    status: .acknowledged,
    message: "We're investigating the issue"
)

// Delete incident (v1 - requires ScopeIncidentsWrite)
try await StatusPageAPI.shared.deleteIncident(id: "incident-id")

// Add incident update (v1 - requires ScopeIncidentsWrite)
try await StatusPageAPI.shared.createIncidentUpdate(
    id: "incident-id",
    message: "Fix has been deployed",
    status: "monitoring"
)

// Acknowledge incident
try await StatusPageAPI.shared.acknowledgeIncident(id: "incident-id")

// Escalate incident
try await StatusPageAPI.shared.escalateIncident(id: "incident-id")

// Resolve incident (v1 - requires ScopeIncidentsWrite)
let resolved = try await StatusPageAPI.shared.resolveIncident(id: "incident-id")

// Assign incident
try await StatusPageAPI.shared.assignIncident(id: "incident-id", userId: "user-id")
```

## Incident Tasks

```swift
// Fetch tasks for an incident
let tasks = try await StatusPageAPI.shared.fetchIncidentTasks(incidentId: "incident-id")

// Create task
let task = try await StatusPageAPI.shared.createIncidentTask(
    incidentId: "incident-id",
    description: "Check database logs"
)

// Update task
let updated = try await StatusPageAPI.shared.updateIncidentTask(
    incidentId: "incident-id",
    taskId: "task-id",
    description: "Updated description",
    completed: true
)

// Delete task
try await StatusPageAPI.shared.deleteIncidentTask(
    incidentId: "incident-id",
    taskId: "task-id"
)
```

## Maintenances

```swift
// Fetch all maintenances (v1 - requires ScopeMaintenancesRead)
let maintenances = try await StatusPageAPI.shared.fetchMaintenances()

// Fetch single maintenance (v1 - requires ScopeMaintenancesRead)
let maintenance = try await StatusPageAPI.shared.fetchMaintenance(id: "maintenance-id")

// Create maintenance (v1 - requires ScopeMaintenancesWrite)
let newMaintenance = try await StatusPageAPI.shared.createMaintenance(
    title: "Database Migration",
    message: "Scheduled maintenance window",
    scheduledFor: Date().addingTimeInterval(3600),
    scheduledUntil: Date().addingTimeInterval(7200),
    affectedComponents: ["component-1"]
)

// Update maintenance (v1 - requires ScopeMaintenancesWrite)
let updated = try await StatusPageAPI.shared.updateMaintenance(
    id: "maintenance-id",
    title: "Updated Title",
    status: "in_progress"
)

// Delete maintenance (v1 - requires ScopeMaintenancesWrite)
try await StatusPageAPI.shared.deleteMaintenance(id: "maintenance-id")
```

## Components

```swift
// Fetch all components (optional filter by status page)
let components = try await StatusPageAPI.shared.fetchComponents(statusPageId: "page-id")
// Or fetch all:
let allComponents = try await StatusPageAPI.shared.fetchComponents()

// Create component
let component = try await StatusPageAPI.shared.createComponent(
    name: "API Server",
    description: "Main API backend",
    groupId: "group-id" // optional
)

// Update component
let updated = try await StatusPageAPI.shared.updateComponent(
    componentId: "component-id",
    name: "Updated Name",
    description: "Updated description",
    status: "operational",
    groupId: "new-group-id"
)

// Delete component
try await StatusPageAPI.shared.deleteComponent(componentId: "component-id")
```

## Component Groups

```swift
// Fetch component groups for a status page (REQUIRED parameter)
let groups = try await StatusPageAPI.shared.fetchGroups(statusPageId: "page-id")

// Create group
let group = try await StatusPageAPI.shared.createGroup(
    statusPageId: "page-id",
    name: "Infrastructure"
)

// Update group
let updated = try await StatusPageAPI.shared.updateGroup(
    groupId: "group-id",
    name: "Updated Name"
)

// Delete group
try await StatusPageAPI.shared.deleteGroup(groupId: "group-id")
```

## Heartbeats

```swift
// Fetch heartbeats for a status page
let heartbeats = try await StatusPageAPI.shared.fetchHeartbeats(statusPageId: "page-id")

// Fetch single heartbeat
let heartbeat = try await StatusPageAPI.shared.fetchHeartbeat(id: "heartbeat-id")

// Create heartbeat
let newHeartbeat = try await StatusPageAPI.shared.createHeartbeat(
    statusPageId: "page-id",
    name: "Background Worker",
    intervalSeconds: 300
)

// Update heartbeat
let updated = try await StatusPageAPI.shared.updateHeartbeat(
    id: "heartbeat-id",
    name: "Updated Name",
    intervalSeconds: 600
)

// Delete heartbeat
try await StatusPageAPI.shared.deleteHeartbeat(id: "heartbeat-id")

// Regenerate token
let regenerated = try await StatusPageAPI.shared.regenerateHeartbeatToken(id: "heartbeat-id")

// Fetch heartbeat pings
let pings = try await StatusPageAPI.shared.fetchHeartbeatPings(id: "heartbeat-id")
```

## On-Call

```swift
// Fetch my on-call status
let status = try await StatusPageAPI.shared.fetchOnCallStatus()

// Take on-call for a schedule
try await StatusPageAPI.shared.takeOnCall(scheduleId: "schedule-id")

// Fetch current on-call members for a schedule
let members = try await StatusPageAPI.shared.fetchOnCallScheduleMembers(scheduleId: "schedule-id")
```

## Teams

```swift
// Fetch all teams
let teams = try await StatusPageAPI.shared.fetchTeams()

// Fetch single team
let team = try await StatusPageAPI.shared.fetchTeam(id: "team-id")

// Fetch team memberships
let memberships = try await StatusPageAPI.shared.fetchTeamMemberships()

// Create team
let newTeam = try await StatusPageAPI.shared.createTeam(name: "Engineering Team")

// Update team
let updated = try await StatusPageAPI.shared.updateTeam(id: "team-id", name: "Updated Name")

// Delete team
try await StatusPageAPI.shared.deleteTeam(id: "team-id")
```

## Analytics

```swift
// Fetch status page analytics
let analytics = try await StatusPageAPI.shared.fetchStatusPageAnalytics(pageId: "page-id")
```

## Notification Channels

```swift
// Fetch all notification channels
let channels = try await StatusPageAPI.shared.fetchNotificationChannels()

// Create notification channel
let channel = try await StatusPageAPI.shared.createNotificationChannel(
    type: "email",
    name: "Team Email",
    config: ["address": "team@example.com"]
)

// Update notification channel
let updated = try await StatusPageAPI.shared.updateNotificationChannel(
    channelId: "channel-id",
    name: "Updated Name",
    config: ["address": "newemail@example.com"]
)

// Delete notification channel
try await StatusPageAPI.shared.deleteNotificationChannel(channelId: "channel-id")

// Test notification channel
try await StatusPageAPI.shared.testNotificationChannel(channelId: "channel-id")

// Resend verification
try await StatusPageAPI.shared.resendChannelVerification(channelId: "channel-id")
```

## Dashboard

```swift
// Fetch dashboard summary
let summary = try await StatusPageAPI.shared.fetchDashboardSummary()
```

## Error Handling

All methods can throw `StatusPageAPI.APIError`:

```swift
do {
    let incidents = try await StatusPageAPI.shared.fetchIncidents()
} catch StatusPageAPI.APIError.missingAPIKey {
    print("API key not configured")
} catch StatusPageAPI.APIError.httpStatus(let code) {
    print("HTTP error: \(code)")
    // 401: Unauthorized (check API key)
    // 403: Forbidden (check scopes)
    // 404: Not found
    // 429: Rate limited
} catch StatusPageAPI.APIError.invalidResponse {
    print("Invalid response from server")
} catch StatusPageAPI.APIError.decoding(let error) {
    print("Failed to decode: \(error)")
} catch {
    print("Unknown error: \(error)")
}
```

## API Scopes

When creating API keys, ensure they have the required scopes:

| Operations | Required Scope |
|------------|----------------|
| Read status pages | `ScopeStatusPagesRead` |
| Read monitors | `ScopeMonitorsRead` |
| Read monitor analytics | `ScopeAnalyticsRead` |
| Read incidents | `ScopeIncidentsRead` |
| Create/update/delete incidents | `ScopeIncidentsWrite` |
| Read maintenances | `ScopeMaintenancesRead` |
| Create/update/delete maintenances | `ScopeMaintenancesWrite` |

## Notes

- All v1 endpoints (`/user/api/v1/*`) enforce scope checks
- Non-v1 endpoints (`/user/api/*`) may have different auth requirements
- The API automatically handles `{"data": ...}` wrapped responses
- Dates are encoded/decoded using ISO8601 format
- Property names automatically convert between snake_case and camelCase
