import { http, httpBinary } from './http.js'; /** * Company-scoped brands (selectedCompanyId from session). * Shape: Brand = { id, name, gsprpinfo | null, pics: BrandPic[] } */ export const brand = { /** * GET /api/brand → { brands: Brand[], total, offset, limit } * @param {{ offset?: number, limit?: number, includeSmallThumbs?: boolean }} [params] */ // #region GET /api/brand — list list(params) { const offset = Number(params?.offset ?? 0); const limit = Number(params?.limit ?? 0); const includeSmallThumbs = params?.includeSmallThumbs; const query = new URLSearchParams(); if (Number.isFinite(offset) && offset > 0) query.set('offset', String(offset)); if (Number.isFinite(limit) && limit > 0) query.set('limit', String(limit)); if (includeSmallThumbs != null) query.set('includeSmallThumbs', includeSmallThumbs ? 'true' : 'false'); const qs = query.toString(); return http(qs ? `/api/brand?${qs}` : '/api/brand'); }, // #endregion /** * POST /api/brand * Body: { name, gsprpinfo? } — insert for the selected company. * Empty name ⇒ 400 Invalid brand. * → 201 { brand: Brand } · 409 Brand already exists */ // #region POST /api/brand — create create(body) { return http('/api/brand', { method: 'POST', body }); }, // #endregion /** * PATCH /api/brand/:id * Body: { name, gsprpinfo? } — rename / update info. * → 200 { id, name, gsprpinfo, touchedArticleCount } · 404 Brand not found */ // #region PATCH /api/brand/:id — rename rename(id, body) { return http(`/api/brand/${encodeURIComponent(id)}`, { method: 'PATCH', body }); }, // #endregion /** * DELETE /api/brand/:id * → 204 No Content · 404 Brand not found */ // #region DELETE /api/brand/:id — delete delete(id) { return http(`/api/brand/${encodeURIComponent(id)}`, { method: 'DELETE' }); }, // #endregion /** * POST /api/brand/:id/image * Accepts full-size image body (Content-Type: image/webp). * → 201 { brand: { id, fullHash, thumbW, thumbH, thumbHash, pics } } */ // #region POST /api/brand/:id/image — addImage addImage(brandId, file) { return httpBinary(`/api/brand/${brandId}/image`, { method: 'POST', contentType: file?.type || 'image/webp', body: file, }); }, // #endregion /** * DELETE /api/brand/:id/image * → 200 { brand: { id, thumbW: null, thumbH: null, thumbHash: null, pics: [] } } */ // #region DELETE /api/brand/:id/image — deleteImage deleteImage(brandId) { return http(`/api/brand/${brandId}/image`, { method: 'DELETE' }); }, // #endregion };