import apiClient from './client';

export interface PhotoUploadResult {
  photo: {
    id: string;
    url: string;
    thumbnailUrl?: string;
    originalUrl?: string;
    storageKey: string;
  };
}

export const photosApi = {
  /**
   * Upload a photo for profile/child
   * Uses multipart/form-data to send file to backend
   * Backend handles image optimization via Sharp and storage via MinIO
   */
  uploadPhoto: async (
    file: File,
    options?: {
      childId?: string;
      type?: string;
      caption?: string;
    }
  ): Promise<PhotoUploadResult> => {
    const formData = new FormData();
    formData.append('photo', file);

    if (options?.childId) {
      formData.append('childId', options.childId);
    }
    if (options?.type) {
      formData.append('type', options.type);
    }
    if (options?.caption) {
      formData.append('caption', options.caption);
    }

    const response = await apiClient.post('/api/v1/photos/upload', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });

    return response.data.data;
  },
};
