import { AxiosRequestConfig } from "axios";
import { initialization } from "./axios";

export const baseURL = import.meta.env.VITE_FETCH_URL
export const axiosRequestConfiguration: AxiosRequestConfig = {
    baseURL,
    responseType: 'json',
    headers: {
        'Content-Type': 'application/json',
    },
};

const req = initialization(axiosRequestConfiguration)

export const fetchProduct =async (productId:string) =>{
   const res=await req.get(`products/${productId}`)
   if(res&&res.status==200){
       return res.data
   }else{
       throw new Error('network went wrong')
   }
}

export const getJobs =  async(department?: string)=>{
    let res
    if(department){
       res = await req.get(`jobs?department=${department}`)
    }else{
        res = await req.get(`jobs`)
    }
    if(res&&res.status==200){
        return res.data
    }else{
        throw new Error('network went wrong')
    }
}