// fe/src/types/shared.ts
// Unified Data Contract - Shared types between frontend and backend
// This file defines the canonical data structures that both systems must conform to

/**
 * Base interfaces that all entities should implement
 */
export interface BaseEntity {
    id: number
    created_at: string
    updated_at: string
    version: number
}

export interface SoftDeletableEntity extends BaseEntity {
    deleted_at?: string | null
    is_deleted: boolean
}

/**
 * Real-time WebSocket event structure
 */
export interface WebSocketEvent<T = any> {
    event: string
    payload: T
    timestamp: string
    user_id?: number
    room?: string
}

/**
 * Optimistic update tracking
 */
export interface OptimisticUpdate<T> {
    id: string
    entity_type: string
    entity_id: number
    operation: 'create' | 'update' | 'delete'
    data: T
    timestamp: string
    status: 'pending' | 'confirmed' | 'failed'
}

/**
 * Conflict resolution data structure
 */
export interface ConflictResolution<T> {
    id: string
    entity_type: string
    entity_id: number
    local_version: number
    server_version: number
    local_data: T
    server_data: T
    resolution_strategy: 'local' | 'server' | 'merge' | 'manual'
    resolved_data?: T
    resolved_at?: string
}

/**
 * Real-time activity tracking
 */
export interface ActivityEvent {
    id: number
    user_id: number
    user_name: string
    group_id?: number
    entity_type: string
    entity_id: number
    action: string
    details?: Record<string, any>
    timestamp: string
}

/**
 * Unified error response structure
 */
export interface APIError {
    error: string
    message: string
    details?: Record<string, any>
    code?: string
    timestamp: string
}

/**
 * Pagination and filtering
 */
export interface PaginationParams {
    page: number
    limit: number
    sort_by?: string
    sort_order?: 'asc' | 'desc'
}

export interface PaginatedResponse<T> {
    items: T[]
    total: number
    page: number
    limit: number
    has_next: boolean
    has_prev: boolean
}

/**
 * Sync delta for offline support
 */
export interface SyncDelta {
    timestamp: string
    operations: Array<{
        id: string
        entity_type: string
        operation: 'create' | 'update' | 'delete'
        entity_id: number
        data?: any
    }>
} 