import { apiClient } from './client'
import type { Lead, LeadFilters, LeadsResponse, LeadResponse, LeadStats, LeadStatus } from '@/types/lead'
import type { ApiResponse } from '@/types/api'

/**
 * Leads API
 */
export const leadsApi = {
  /**
   * Get paginated list of leads
   */
  async getLeads(
    page = 1,
    perPage = 20,
    filters?: LeadFilters
  ): Promise<LeadsResponse> {
    return apiClient.get<LeadsResponse>('leads', {
      page,
      per_page: perPage,
      ...filters,
    })
  },
  
  /**
   * Get single lead by ID
   */
  async getLead(id: number): Promise<LeadResponse> {
    return apiClient.get<LeadResponse>(`leads/${id}`)
  },
  
  /**
   * Update lead
   */
  async updateLead(id: number, data: Partial<Lead>): Promise<ApiResponse> {
    return apiClient.put<ApiResponse>(`leads/${id}`, data)
  },
  
  /**
   * Update lead status
   */
  async updateLeadStatus(id: number, status: LeadStatus): Promise<ApiResponse> {
    return apiClient.put<ApiResponse>(`leads/${id}`, { lead_status: status })
  },
  
  /**
   * Delete lead
   */
  async deleteLead(id: number): Promise<ApiResponse> {
    return apiClient.delete<ApiResponse>(`leads/${id}`)
  },
  
  /**
   * Get lead statistics
   */
  async getLeadStats(): Promise<ApiResponse<LeadStats>> {
    return apiClient.get<ApiResponse<LeadStats>>('leads/stats')
  },
}










