/**
 * Common Strapi types and utilities
 */

// Base Strapi response structure
export interface StrapiResponse<T> {
  data: T;
  meta: {
    pagination?: {
      page: number;
      pageSize: number;
      pageCount: number;
      total: number;
    };
  };
}

// Single type response (no array)
export interface StrapiSingleTypeResponse<T> {
  data: T;
  meta: Record<string, any>;
}

// Collection type response (array)
export interface StrapiCollectionResponse<T> {
  data: T[];
  meta: {
    pagination: {
      page: number;
      pageSize: number;
      pageCount: number;
      total: number;
    };
  };
}

// Base attributes for all Strapi content types
export interface StrapiBaseAttributes {
  createdAt: string;
  updatedAt: string;
  publishedAt?: string;
}

// Media/File types
export interface StrapiMediaFormat {
  name: string;
  hash: string;
  ext: string;
  mime: string;
  width: number;
  height: number;
  size: number;
  url: string;
  path?: string;
}

export interface StrapiMedia extends StrapiBaseAttributes {
  id: number;
  name: string;
  alternativeText: string | null;
  caption: string | null;
  width: number | null;
  height: number | null;
  formats: {
    thumbnail?: StrapiMediaFormat;
    small?: StrapiMediaFormat;
    medium?: StrapiMediaFormat;
    large?: StrapiMediaFormat;
  } | null;
  hash: string;
  ext: string;
  mime: string;
  size: number;
  url: string;
  previewUrl: string | null;
  provider: string;
  provider_metadata: any | null;
}

// Error response
export interface StrapiError {
  status: number;
  name: string;
  message: string;
  details?: Record<string, any>;
}

export interface StrapiErrorResponse {
  data: null;
  error: StrapiError;
}

// Query parameters
export interface StrapiQueryParams {
  populate?: string | string[] | Record<string, any>;
  fields?: string[];
  filters?: Record<string, any>;
  sort?: string | string[];
  pagination?: {
    page?: number;
    pageSize?: number;
    start?: number;
    limit?: number;
  };
  publicationState?: 'live' | 'preview';
  locale?: string;
}

// Utility type to extract data from Strapi response
export type ExtractStrapiData<T> = T extends StrapiResponse<infer U> ? U : never;

// Utility type for relations
export interface StrapiRelation<T> {
  data: T | null;
}

export interface StrapiRelationMany<T> {
  data: T[];
}

