// Decision API service for managing listing decisions (like/dislike/seen) import type { AuthUser } from '@/auth/types'; import type { DecisionType, ListingDecision } from '@/types'; import { apiRequest } from './apiClient'; export async function fetchDecisions(user: AuthUser): Promise { return apiRequest(user, '/api/decisions'); } export async function setDecision( user: AuthUser, listingId: number, decision: DecisionType, listingType: 'RENT' | 'BUY' = 'RENT', priceAtDecision?: number | null, ): Promise { const body: Record = { decision, listing_type: listingType }; // Only send the price column for 'seen' — the backend already drops it for // other decision types, but keeping the payload tight saves bytes. if (decision === 'seen' && typeof priceAtDecision === 'number' && Number.isFinite(priceAtDecision)) { body.price_at_decision = priceAtDecision; } return apiRequest(user, `/api/decisions/${listingId}`, { method: 'PUT', body, }); } export async function clearDecision( user: AuthUser, listingId: number, listingType: 'RENT' | 'BUY' = 'RENT', ): Promise { await apiRequest(user, `/api/decisions/${listingId}`, { method: 'DELETE', params: { listing_type: listingType }, }); }