import { httpClient } from './httpClient';

export class AppApi {
  static async analyzeTelegramImport(file: File) {
    const formData = new FormData();
    formData.append('file', file);
    return httpClient.request('/import/telegram/analyze', {
      method: 'POST',
      body: formData,
    });
  }

  static async executeTelegramImport(req: { token: string; mapping: Record<string, string>; groupName?: string }) {
    return httpClient.request('/import/telegram/execute', {
      method: 'POST',
      body: JSON.stringify(req),
    });
  }

  static async getTrendingGifs(page: number = 1) {
    return httpClient.request<any>(`/klipy/trending?page=${page}`);
  }

  static async searchKlipyGifs(query: string, page: number = 1) {
    return httpClient.request<any>(`/klipy/search?q=${encodeURIComponent(query)}&page=${page}`);
  }

  static async getRecentGifs(page: number = 1) {
    return httpClient.request<any>(`/klipy/recent?page=${page}`);
  }

  static async getGifCategories(countryCode: string = 'RU') {
    return httpClient.request<any>(`/klipy/categories?countryCode=${countryCode}`);
  }

  static async markGifShared(gifId: string, query: string = '') {
    return httpClient.request<void>(`/klipy/${gifId}/share?q=${encodeURIComponent(query)}`, {
      method: 'POST'
    });
  }
}
