import { Client } from './client'; import { Collection, CollectionDetail, CollectionType, Region, Locale, SortBy } from './collections'; import { LocaleString } from './stocks'; export enum CollectionStatus { Active = 'active', Inactive = 'inactive', } export interface CreateCustomThemeParams { title: LocaleString; description?: LocaleString; region?: Region[]; image_url?: string; image?: string; avatar_url?: string; stocks: string[]; // Using string instead of ObjectID order?: number; status: CollectionStatus; meta_data?: Record; } export interface UpdateCustomThemeParams { title?: LocaleString; description?: LocaleString; image_url?: string; image?: string; avatar_url?: string; stockIds?: string[]; // Using string instead of ObjectID status?: CollectionStatus; meta_data?: Record; } export class CustomThemeClient extends Client { private async getAllCollectionsPrivate(collectionType: CollectionType, locale: Locale, region?: Region): Promise { const params = { locale, ...(region != null && { region }), }; return this.sendRequest({ method: 'GET', url: `/api/v1/${collectionType}`, params: params, }); } private async getCollectionDetailPrivate(id: string, collectionType: CollectionType, locale: Locale, sortBy: SortBy | null): Promise { const params = { locale, ...(sortBy != null && { sortBy }), }; return this.sendRequest({ method: 'GET', url: `/api/v1/${collectionType}/${id}`, params: params, }); } async getAllCustomThemes(locale: Locale, region?: Region): Promise { return this.getAllCollectionsPrivate(CollectionType.CustomTheme, locale, region); } async getCustomThemeDetail(id: string, locale: Locale, sortBy: SortBy | null): Promise { return this.getCollectionDetailPrivate(id, CollectionType.CustomTheme, locale, sortBy); } async createCustomTheme(params: CreateCustomThemeParams): Promise { const response = await this.sendRequest<{ id: string }>({ method: 'POST', url: `/api/v1/custom-theme`, data: params, }); return response.id; } async updateCustomTheme(id: string, params: UpdateCustomThemeParams): Promise { await this.sendRequest({ method: 'PATCH', url: `/api/v1/custom-theme/${id}`, data: params, }); } async deleteCustomTheme(id: string): Promise { await this.sendRequest({ method: 'DELETE', url: `/api/v1/custom-theme/${id}`, }); } }