/** * Composable for policy API operations * Handles quote submission and acceptance */ export function usePolicyApi() { const { $policy } = useNuxtApp() const toast = useToast() const router = useRouter() /** * Submit a policy quote request */ async function submitPolicyQuote(payload: { policy_type: 'car' | 'life' | 'fire_structure' | 'fire_contents' insured: any buyer: any policy_details: any selected_providers: Array<{ provider_id: string; email: string }> }) { try { const data = await $policy('/policies', { method: 'POST', body: payload }) as any toast.add({ title: 'Quote submitted successfully', color: 'green' }) return data } catch (e: any) { toast.add({ title: 'Failed to submit quote', description: e?.data?.error ?? e.message, color: 'red' }) throw e } } /** * Accept a quote plan and trigger solicitation */ async function acceptQuote(applicationId: string, acceptedPlanId: string, acceptedBy: string) { try { const data = await $policy(`/policies/${applicationId}/accept`, { method: 'POST', body: { accepted_plan_id: acceptedPlanId, accepted_by: acceptedBy } }) as any toast.add({ title: 'Plan accepted successfully', color: 'green' }) return data } catch (e: any) { toast.add({ title: 'Failed to accept plan', description: e?.data?.error ?? e.message, color: 'red' }) throw e } } return { submitPolicyQuote, acceptQuote } }