/**
 * API Response Utilities
 */
import { AxiosResponse } from 'axios';

export const extractData = <T>(response: AxiosResponse<T> | { data?: T }): T => {
  if ('data' in response && response.data !== undefined) {
    return response.data;
  }
  return response as unknown as T;
};

export const extractPaginatedData = <T>(response: AxiosResponse<{ items: T[]; pagination?: any }> | { data?: { items: T[]; pagination?: any } }): { items: T[]; pagination: any } => {
  const data = 'data' in response ? response.data : undefined;
  if (data && 'items' in data) {
    return {
      items: data.items,
      pagination: data.pagination ?? {}
    };
  }
  return { items: [] as T[], pagination: {} };
};
