/** Service for business-related API calls */
import { apiClient } from './apiClient'
import type { Business } from '@/types'

export const businessService = {
    /** Get all businesses */
    async getAllBusinesses(): Promise<Business[]> {
        const response = await apiClient.get<Business[]>('/api/businesses')
        return response.data
    },

    /** Get a single business by ID */
    async getBusiness(id: string): Promise<Business> {
        const response = await apiClient.get<Business>(`/api/businesses/${id}`)
        return response.data
    },

    /** Create a new business */
    async createBusiness(businessData: FormData): Promise<Business> {
        const response = await apiClient.post<Business>('/api/businesses', businessData, {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
        return response.data
    },

    /** Update an existing business */
    async updateBusiness(id: string, businessData: FormData): Promise<Business> {
        const response = await apiClient.patch<Business>(`/api/businesses/${id}`, businessData, {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
        return response.data
    },

    /** Delete a business */
    async deleteBusiness(id: string): Promise<void> {
        await apiClient.delete(`/api/businesses/${id}`)
    },
}
