/**
 * Common Types
 * Shared type definitions for OrbiQuant IA
 */

// Pagination
export interface PaginationParams {
  page?: number;
  perPage?: number;
  sortBy?: string;
  sortOrder?: 'asc' | 'desc';
}

export interface PaginatedResult<T> {
  data: T[];
  pagination: {
    page: number;
    perPage: number;
    total: number;
    totalPages: number;
    hasNext: boolean;
    hasPrev: boolean;
  };
}

// API Response
export interface ApiResponse<T = unknown> {
  success: boolean;
  data?: T;
  message?: string;
  error?: ApiError;
  meta?: Record<string, unknown>;
}

export interface ApiError {
  code: string;
  message: string;
  field?: string;
  details?: unknown;
}

// Request context
export interface RequestContext {
  userId?: string;
  sessionId?: string;
  ip?: string;
  userAgent?: string;
  traceId?: string;
}

// Date range filter
export interface DateRangeFilter {
  startDate?: Date;
  endDate?: Date;
}

// Search filter
export interface SearchFilter {
  query?: string;
  fields?: string[];
}

// ID params
export interface IdParams {
  id: string;
}

// Timestamps
export interface Timestamps {
  createdAt: Date;
  updatedAt: Date;
}

export interface SoftDelete {
  deletedAt?: Date | null;
}

// Base entity
export interface BaseEntity extends Timestamps {
  id: string;
}

// Audit metadata
export interface AuditMetadata {
  createdBy?: string;
  updatedBy?: string;
  createdAt: Date;
  updatedAt: Date;
}

// File upload
export interface FileUpload {
  filename: string;
  mimetype: string;
  size: number;
  buffer: Buffer;
}

export interface UploadedFile {
  url: string;
  key: string;
  filename: string;
  mimetype: string;
  size: number;
}

// Webhook payload
export interface WebhookPayload<T = unknown> {
  event: string;
  data: T;
  timestamp: string;
  signature?: string;
}
