// خدمة عناوين العملاء — كل نداءات الـ API الخاصة بالعناوين تكون هنا فقط // Mirrors user.service.ts pattern: explicit token param, buildPayload helper. import { get, post, put, patch, del } from "./api"; import type { ApiResponse, ClientAddress, ClientAddressFormData, } from "../types/client"; const base = (clientId: string) => `client/${clientId}/addresses`; export const clientAddressService = { /** جلب جميع عناوين عميل معين */ getAll: (clientId: string, token: string | null) => get>(base(clientId), token), /** جلب عنوان واحد بالـ ID */ getById: (clientId: string, addressId: string, token: string | null) => get>(`${base(clientId)}/${addressId}`, token), /** إضافة عنوان جديد لعميل */ create: (clientId: string, data: ClientAddressFormData, token: string | null) => post>(base(clientId), buildPayload(clientId, data), token), /** تعديل عنوان موجود */ update: (clientId: string, addressId: string, data: ClientAddressFormData, token: string | null) => put>(`${base(clientId)}/${addressId}`, buildPayload(clientId, data), token), /** حذف عنوان */ delete: (clientId: string, addressId: string, token: string | null) => del(`${base(clientId)}/${addressId}`, token), /** تعيين عنوان كعنوان رئيسي — الباكند يُلغي الاختيار عن الباقين */ setPrimary: (clientId: string, addressId: string, token: string | null) => patch>(`${base(clientId)}/${addressId}/primary`, {}, token), }; /** تحويل بيانات النموذج إلى payload */ function buildPayload(clientId: string, data: ClientAddressFormData): Record { return { clientId, label: data.label.trim(), street: data.street.trim(), city: data.city.trim(), state: data.state.trim(), postalCode: data.postalCode.trim(), country: data.country.trim(), isPrimary: data.isPrimary, }; }