import {useFormPayload} from "~/composables/useFormPayload";

export const useFetchWrapped = <TypeReq, TypeResp>(
    action: string,
    payload?: TypeReq,
    options?: {
        method?: 'GET' | 'POST'
        headers?: Record<string, string>
        baseURL?: string
    }
) => {
    const runtimeConfig = useRuntimeConfig()
    return $fetch<TypeResp>('/', {
        baseURL: options?.baseURL || runtimeConfig.public.API_BASE,
        method: options?.method || 'POST',
        query: {
            s: action
        },
        body: useFormPayload(payload as object)
    })
}