import { GHLClient } from '../client'; import { GHLCustomField } from '@/types/ghl'; export interface CustomValue { id: string; name: string; value: string; } export class CustomFieldsService { constructor( private client: GHLClient, private locationId: string ) {} // Get all custom fields for a location async getCustomFields(): Promise { const response = await this.client.get(`/locations/${this.locationId}/customFields`); return (response as any).customFields || []; } // Create a new custom field async createCustomField(data: { name: string; dataType: 'TEXT' | 'NUMBER' | 'DATE' | 'CHECKBOX' | 'LIST'; position?: number; }): Promise { return this.client.post(`/locations/${this.locationId}/customFields`, data); } // Update a custom field async updateCustomField(fieldId: string, data: { name?: string; position?: number }): Promise { return this.client.put(`/locations/${this.locationId}/customFields/${fieldId}`, data); } // Delete a custom field async deleteCustomField(fieldId: string): Promise { await this.client.delete(`/locations/${this.locationId}/customFields/${fieldId}`); } // Get all custom values (for message templates) async getCustomValues(): Promise { const response = await this.client.get(`/locations/${this.locationId}/customValues`); return (response as any).customValues || []; } // Update a custom value async updateCustomValue(valueId: string, value: string): Promise { return this.client.put(`/locations/${this.locationId}/customValues/${valueId}`, { value }); } // Create a custom value async createCustomValue(name: string, value: string): Promise { return this.client.post(`/locations/${this.locationId}/customValues`, { name, value }); } // Bulk update custom values (useful for onboarding) async bulkUpdateCustomValues(values: { name: string; value: string }[]): Promise { const existingValues = await this.getCustomValues(); for (const { name, value } of values) { const existing = existingValues.find(v => v.name === name); if (existing) { await this.updateCustomValue(existing.id, value); } else { await this.createCustomValue(name, value); } } } }