import axiosInstance from '@/utills/axiosInstance';
import { type FilterOptions } from './interface';

export async function getAllLeadRequest(filter: FilterOptions): Promise<any> {
  try {
    const response = await axiosInstance.get('/api/v1/lead-requests', {
      params: filter,
    });
    if (response !== undefined) {
      return response.data;
    } else {
      throw new Error('Failed to fetch Lead Requests');
    }
  } catch (error) {
    console.error(error);
    throw error;
  }
}

export async function getLaunch(id: number): Promise<any> {
  const response = await axiosInstance.get(`/api/v1/launch/${id}`);
  return response.data;
}

export async function updateLeadStatus(leadId: number, action: string): Promise<any> {
  try {
    const response = await axiosInstance.patch(`/api/v1/lead-requests/${leadId}`, {
      status: action, // Add any other data needed for the update
    });

    if (response !== undefined) {
      return response.data; // Assuming the data you need is in the 'data' property of the response
    } else {
      throw new Error('Failed to update Lead Status');
    }
  } catch (error) {
    console.error(error);
    throw error;
  }
}

export async function addLeadRequests(data: any): Promise<any> {
  try {
    const response = await axiosInstance.post('/api/v1/lead-requests', data);
    if (response !== undefined) {
      return response.data;
    } else {
      throw new Error('Failed to add Lead Requests');
    }
  } catch (error) {
    console.error(error);
    throw error;
  }
}

export async function getCreatedByLeadRequest(): Promise<any> {
  try {
    const response = await axiosInstance.get('/api/v1/lead-requests/lead-request/created-by');
    if (response !== undefined) {
      return response.data;
    } else {
      throw new Error('Failed to fetch Lead Requests');
    }
  } catch (error) {
    console.error(error);
    throw error;
  }
}
export async function getLaunchesAndProjectsLeadRequest(): Promise<any> {
  try {
    const response = await axiosInstance.get('/api/v1/lead-requests/lead-request/launch-filter');
    if (response !== undefined) {
      return response.data;
    } else {
      throw new Error('Failed to fetch Lead Requests');
    }
  } catch (error) {
    console.error(error);
    throw error;
  }
}
