/**
 * Admin CSV Rates API Client
 *
 * ADMIN-only endpoints for managing CSV rate files
 */

import { get, post, del, upload } from '../client';
import type { CsvRateUploadResponse, SuccessResponse } from '@/types/api';

// TODO: These types should be moved to @/types/api.ts
export interface CsvFileInfo {
  filename: string;
  size: number;
  uploadedAt: string;
  rowCount?: number;
  companyEmail?: string | null;
}

export interface CsvFileListResponse {
  files: CsvFileInfo[];
}

/**
 * Upload CSV rate file (ADMIN only)
 * POST /api/v1/admin/csv-rates/upload
 */
export async function uploadCsvRates(formData: FormData): Promise<CsvRateUploadResponse> {
  return upload<CsvRateUploadResponse>('/api/v1/admin/csv-rates/upload', formData);
}

/**
 * List all CSV files
 * GET /api/v1/admin/csv-rates/files
 */
export async function listCsvFiles(): Promise<CsvFileListResponse> {
  return get<CsvFileListResponse>('/api/v1/admin/csv-rates/files');
}

/**
 * Delete CSV file
 * DELETE /api/v1/admin/csv-rates/files/:filename
 */
export async function deleteCsvFile(filename: string): Promise<SuccessResponse> {
  return del<SuccessResponse>(`/api/v1/admin/csv-rates/files/${encodeURIComponent(filename)}`);
}

/**
 * Get CSV file statistics
 * GET /api/v1/admin/csv-rates/stats/:filename
 */
export async function getCsvFileStats(filename: string): Promise<any> {
  return get<any>(`/api/v1/admin/csv-rates/stats/${encodeURIComponent(filename)}`);
}

/**
 * Convert CSV format (FOB FRET to Standard)
 * POST /api/v1/admin/csv-rates/convert
 */
export async function convertCsvFormat(data: {
  sourceFile: string;
  targetFormat: 'STANDARD';
}): Promise<any> {
  return post<any>('/api/v1/admin/csv-rates/convert', data);
}
