/**
 * Base user type - extend this for your app's user model.
 */
export interface BaseUser {
    id?: number | string
    email?: string
    username?: string
    is_staff?: boolean
    is_superuser?: boolean
    [key: string]: unknown
}

/**
 * Auth state derived from user.
 */
export interface AuthDetails {
    isAuthenticated: boolean
    isStaff: boolean
    isSuperuser: boolean
}

/**
 * Configuration for route guards.
 */
export interface AuthRoutes {
    login: string
    authenticated: string
}

/**
 * JWT token structure.
 */
export interface JWTTokens {
    accessToken: string
    refreshToken: string
    expiresAt: number // Unix timestamp in ms
}

/**
 * JWT endpoint configuration.
 */
export interface JWTConfig {
    /** Base URL for API calls (default: '' - use relative URLs) */
    baseUrl?: string
    /** mizan server function endpoint (default: /api/mizan/call/) */
    endpoint?: string
    /** Seconds before expiry to trigger refresh (default: 30) */
    refreshBuffer?: number
    /** Auto-obtain tokens on mount (default: true) */
    autoObtain?: boolean
    /** Auto-refresh tokens before expiry (default: true) */
    autoRefresh?: boolean
}

/**
 * JWT state and methods.
 */
export interface JWTState {
    tokens: JWTTokens | null
    isLoading: boolean
    error: Error | null
    obtainTokens: () => Promise<JWTTokens | null>
    refreshTokens: () => Promise<JWTTokens | null>
    clearTokens: () => void
    getAccessToken: () => Promise<string | null>
}
