
import { apiClient } from './apiClient'
import { ShippingSettings } from '../types/shipping'

export interface CalculateShippingRequest {
    buyer_id: string
    order_total_cents: number
    items: {
        seller_id: string
        product_id: string
        quantity: number
        price_cents: number
    }[]
}

export interface CalculateShippingResponse {
    options: {
        seller_id: string
        delivery_fee_cents: number
        distance_km: number
        estimated_days: number
        pickup_available: boolean
        pickup_address?: string
        pickup_hours?: string
    }[]
}

export const shippingService = {
    getSettings: async (vendorId: string): Promise<ShippingSettings> => {
        const response = await apiClient.get<ShippingSettings>(`/v1/shipping/settings/${vendorId}`)
        return response
    },

    calculate: async (data: CalculateShippingRequest) => {
        const response = await apiClient.post<CalculateShippingResponse>('/v1/shipping/calculate', data)
        return response
    }
}
