/**
 * Common API response and utility types used across the CRM.
 */

/** Generic wrapper for all API responses */
export interface ApiResponse<T> {
  data: T;
  success: true;
}

/** Wrapper for API error responses */
export interface ApiErrorResponse {
  success: false;
  error: ApiError;
}

/** Paginated list response */
export interface PaginatedResponse<T> {
  data: T[];
  pagination: {
    page: number;
    pageSize: number;
    total: number;
    totalPages: number;
    hasNextPage: boolean;
    hasPreviousPage: boolean;
  };
}

/** Standard API error shape */
export interface ApiError {
  code: string;
  message: string;
  field?: string;
  details?: Record<string, unknown>;
}

/** Sort configuration for list queries */
export interface SortConfig<T extends string = string> {
  field: T;
  direction: 'asc' | 'desc';
}

/** Filter configuration for list queries */
export interface FilterConfig {
  field: string;
  operator:
    | 'eq'
    | 'neq'
    | 'gt'
    | 'gte'
    | 'lt'
    | 'lte'
    | 'like'
    | 'in'
    | 'notIn'
    | 'isNull'
    | 'isNotNull';
  value: string | number | boolean | string[] | number[] | null;
}

/** Standard list query parameters */
export interface ListQueryParams {
  page?: number;
  pageSize?: number;
  sort?: SortConfig;
  filters?: FilterConfig[];
  search?: string;
}

/** Standard mutation response */
export interface MutationResponse {
  success: boolean;
  id?: string;
  message?: string;
}
