> ## Documentation Index
> Fetch the complete documentation index at: https://docs.go-mizu.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# API Reference

> Complete API documentation for the mobile package.

Complete reference documentation for `github.com/go-mizu/mizu/mobile`.

## Middleware

### New

```go theme={null}
func New() mizu.Middleware
```

Creates mobile middleware with default options.

### WithOptions

```go theme={null}
func WithOptions(opts Options) mizu.Middleware
```

Creates mobile middleware with custom options.

### VersionMiddleware

```go theme={null}
func VersionMiddleware(opts VersionOptions) mizu.Middleware
```

Creates API versioning middleware.

### UniversalLinkMiddleware

```go theme={null}
func UniversalLinkMiddleware(cfg UniversalLinkConfig) mizu.Middleware
```

Creates middleware that serves deep link verification files.

## Types

### Options

```go theme={null}
type Options struct {
    RequireDeviceID       bool
    RequireAppVersion     bool
    AllowedPlatforms      []Platform
    MinAppVersion         string
    SkipPaths             []string
    SkipUserAgent         bool
    OnMissingHeader       func(c *mizu.Ctx, header string) error
    OnUnsupportedPlatform func(c *mizu.Ctx, platform Platform) error
    OnOutdatedApp         func(c *mizu.Ctx, version, minimum string) error
}
```

### Device

```go theme={null}
type Device struct {
    Platform     Platform
    OSVersion    string
    AppVersion   string
    AppBuild     string
    DeviceID     string
    DeviceModel  string
    Locale       string
    Timezone     string
    PushToken    string
    PushProvider PushProvider
    UserAgent    string
}
```

### Platform

```go theme={null}
type Platform string

const (
    PlatformIOS     Platform = "ios"
    PlatformAndroid Platform = "android"
    PlatformWindows Platform = "windows"
    PlatformMacOS   Platform = "macos"
    PlatformWeb     Platform = "web"
    PlatformUnknown Platform = "unknown"
)

func (p Platform) String() string
func (p Platform) IsMobile() bool
func (p Platform) IsDesktop() bool
func (p Platform) IsNative() bool
```

### Version

```go theme={null}
type Version struct {
    Major int
    Minor int
}

func ParseVersion(s string) (Version, error)
func (v Version) String() string
func (v Version) IsZero() bool
func (v Version) Compare(other Version) int
func (v Version) AtLeast(major, minor int) bool
func (v Version) Before(major, minor int) bool
```

### VersionOptions

```go theme={null}
type VersionOptions struct {
    Header        string
    QueryParam    string
    PathPrefix    bool
    Default       Version
    Supported     []Version
    Deprecated    []Version
    EchoVersion   bool
    OnUnsupported func(c *mizu.Ctx, v Version) error
}
```

### Error

```go theme={null}
type Error struct {
    Code    string         `json:"code"`
    Message string         `json:"message"`
    Details map[string]any `json:"details,omitempty"`
    TraceID string         `json:"trace_id,omitempty"`
}

func NewError(code, message string) *Error
func (e *Error) WithDetails(key string, value any) *Error
func (e *Error) WithTraceID(traceID string) *Error
func (e *Error) Error() string
```

### SyncToken

```go theme={null}
type SyncToken string

func NewSyncToken(t time.Time) SyncToken
func (t SyncToken) Time() time.Time
func (t SyncToken) String() string
func (t SyncToken) IsEmpty() bool
```

### SyncRequest

```go theme={null}
type SyncRequest struct {
    Token     SyncToken
    Resources []string
    FullSync  bool
    Limit     int
}

func ParseSyncRequest(c *mizu.Ctx) SyncRequest
func (r SyncRequest) Since() time.Time
func (r SyncRequest) IsInitial() bool
```

### Delta

```go theme={null}
type Delta[T any] struct {
    Created []T      `json:"created,omitempty"`
    Updated []T      `json:"updated,omitempty"`
    Deleted []string `json:"deleted,omitempty"`
}

func (d Delta[T]) IsEmpty() bool
func (d Delta[T]) Count() int
```

### SyncDelta

```go theme={null}
type SyncDelta[T any] struct {
    Delta[T]
    SyncToken SyncToken `json:"sync_token"`
    HasMore   bool      `json:"has_more"`
    FullSync  bool      `json:"full_sync,omitempty"`
}

func NewSyncDelta[T any](delta Delta[T], token SyncToken, hasMore bool) SyncDelta[T]
func NewFullSyncDelta[T any](delta Delta[T], token SyncToken, hasMore bool) SyncDelta[T]
```

### PushToken

```go theme={null}
type PushToken struct {
    Token      string       `json:"token"`
    Provider   PushProvider `json:"provider"`
    DeviceID   string       `json:"device_id,omitempty"`
    Sandbox    bool         `json:"sandbox,omitempty"`
    CreatedAt  time.Time    `json:"created_at,omitempty"`
    UpdatedAt  time.Time    `json:"updated_at,omitempty"`
    AppVersion string       `json:"app_version,omitempty"`
}

func ParsePushToken(c *mizu.Ctx) *PushToken
```

### PushProvider

```go theme={null}
type PushProvider string

const (
    PushAPNS PushProvider = "apns"
    PushFCM  PushProvider = "fcm"
    PushWNS  PushProvider = "wns"
)
```

### PushPayload

```go theme={null}
type PushPayload struct {
    Title            string         `json:"title,omitempty"`
    Body             string         `json:"body,omitempty"`
    Badge            *int           `json:"badge,omitempty"`
    Sound            string         `json:"sound,omitempty"`
    Data             map[string]any `json:"data,omitempty"`
    Category         string         `json:"category,omitempty"`
    ThreadID         string         `json:"thread_id,omitempty"`
    ChannelID        string         `json:"channel_id,omitempty"`
    CollapseKey      string         `json:"collapse_key,omitempty"`
    Priority         string         `json:"priority,omitempty"`
    TTL              int            `json:"ttl,omitempty"`
    ContentAvailable bool           `json:"content_available,omitempty"`
    MutableContent   bool           `json:"mutable_content,omitempty"`
}

func (p *PushPayload) WithData(key string, value any) *PushPayload
func (p *PushPayload) SetBadge(n int) *PushPayload
func (p *PushPayload) ToAPNS() map[string]any
func (p *PushPayload) ToFCM() map[string]any
```

### DeepLink

```go theme={null}
type DeepLink struct {
    Scheme   string
    Host     string
    Paths    []string
    Fallback string
}

func (d DeepLink) AppleAppSiteAssociation(teamID, bundleID string) []byte
func (d DeepLink) AssetLinks(packageName, fingerprint string) []byte
```

### AppInfo

```go theme={null}
type AppInfo struct {
    CurrentVersion     string            `json:"current_version"`
    MinimumVersion     string            `json:"minimum_version"`
    UpdateURL          string            `json:"update_url"`
    ReleaseNotes       string            `json:"release_notes,omitempty"`
    ReleasedAt         time.Time         `json:"released_at,omitempty"`
    ForceUpdate        bool              `json:"force_update"`
    MaintenanceMode    bool              `json:"maintenance_mode"`
    MaintenanceMessage string            `json:"maintenance_message,omitempty"`
    MaintenanceEndTime *time.Time        `json:"maintenance_end_time,omitempty"`
    Features           map[string]bool   `json:"features,omitempty"`
}
```

## Functions

### DeviceFromCtx

```go theme={null}
func DeviceFromCtx(c *mizu.Ctx) *Device
```

Extracts Device from request context.

### VersionFromCtx

```go theme={null}
func VersionFromCtx(c *mizu.Ctx) Version
```

Extracts Version from request context.

### SendError

```go theme={null}
func SendError(c *mizu.Ctx, status int, err *Error) error
```

Sends a structured error response.

### SetSyncToken

```go theme={null}
func SetSyncToken(c *mizu.Ctx, token SyncToken)
```

Sets the sync token response header.

### ValidateToken

```go theme={null}
func ValidateToken(token string, provider PushProvider) bool
```

Validates a push token format.

### ValidateAPNS

```go theme={null}
func ValidateAPNS(token string) bool
```

Validates APNS token format.

### ValidateFCM

```go theme={null}
func ValidateFCM(token string) bool
```

Validates FCM token format.

### CheckUpdate

```go theme={null}
func CheckUpdate(clientVersion, latestVersion, minimumVersion string) UpdateStatus
```

Compares client version against store versions.

### NewStaticAppInfo

```go theme={null}
func NewStaticAppInfo(currentVersion, minVersion, updateURL string) *StaticAppInfo
```

Creates a StaticAppInfo provider.

### NewIOSStoreURL

```go theme={null}
func NewIOSStoreURL(appID string) string
```

Creates an iOS App Store URL.

### NewAndroidStoreURL

```go theme={null}
func NewAndroidStoreURL(packageName string) string
```

Creates a Google Play Store URL.

## Constants

### Error Codes

```go theme={null}
const (
    ErrInvalidRequest  = "invalid_request"
    ErrUnauthorized    = "unauthorized"
    ErrForbidden       = "forbidden"
    ErrNotFound        = "not_found"
    ErrConflict        = "conflict"
    ErrValidation      = "validation_error"
    ErrRateLimited     = "rate_limited"
    ErrUpgradeRequired = "upgrade_required"
    ErrMaintenance     = "maintenance"
    ErrInternal        = "internal_error"
)
```

### Headers

```go theme={null}
const (
    HeaderDeviceID    = "X-Device-ID"
    HeaderAppVersion  = "X-App-Version"
    HeaderAppBuild    = "X-App-Build"
    HeaderDeviceModel = "X-Device-Model"
    HeaderPlatform    = "X-Platform"
    HeaderOSVersion   = "X-OS-Version"
    HeaderTimezone    = "X-Timezone"
    HeaderLocale      = "X-Locale"
    HeaderPushToken   = "X-Push-Token"
    HeaderAPIVersion  = "X-API-Version"
    HeaderSyncToken   = "X-Sync-Token"
    HeaderIdempotency = "X-Idempotency-Key"
    HeaderRequestID   = "X-Request-ID"
    HeaderMinVersion  = "X-Min-App-Version"
    HeaderDeprecated  = "X-API-Deprecated"
)
```
