/**
 * Mizan TypeScript Adapter — Shared Types
 */

export class ReactContext {
    constructor(public readonly name: string) {
        if (!name) throw new Error('ReactContext name must be non-empty')
    }
}

export type AffectsTarget = ReactContext | string

export interface ClientOptions {
    context?: ReactContext | string
    affects?: AffectsTarget | AffectsTarget[]
    private?: boolean
    route?: string
    methods?: string[]
    auth?: boolean
    rev?: number
    cache?: number | false
}

export interface ParamDef {
    name: string
    type: string
    required: boolean
}

export interface RegistryEntry {
    name: string
    fn: (...args: any[]) => Promise<any>
    context?: string
    affects?: Array<{ type: 'context' | 'function'; name: string; context?: string }>
    params: ParamDef[]
    private: boolean
    viewPath: boolean
    route?: string
    methods?: string[]
    auth?: boolean
    rev?: number
    cache?: number | false
}

export interface ManifestContext {
    functions: Array<{ name: string; path: 'rpc' | 'view' }>
    endpoints: string[]
    params: string[]
    user_scoped: boolean
    render_strategy: 'psr' | 'dynamic_cached'
    page_routes?: string[]
}

export interface ManifestMutation {
    affects: string[]
    auto_scoped_params?: string[]
    private?: boolean
    route?: string
    methods?: string[]
}

export interface EdgeManifest {
    version: number
    contexts: Record<string, ManifestContext>
    mutations: Record<string, ManifestMutation>
}
