import api from './api';
import { CustomFieldDefinition } from '../types/customFields';

export const customFieldService = {
  getAll: async () => {
    const response = await api.get<CustomFieldDefinition[]>('/custom-fields');
    return response.data;
  },
  getByEntity: async (entityName: string) => {
    const response = await api.get<CustomFieldDefinition[]>(`/custom-fields/entity/${entityName}`);
    return response.data;
  },
  create: async (definition: Omit<CustomFieldDefinition, 'id'>) => {
    const response = await api.post<CustomFieldDefinition>('/custom-fields', definition);
    return response.data;
  },
  update: async (id: number, definition: CustomFieldDefinition) => {
    const response = await api.put<CustomFieldDefinition>(`/custom-fields/${id}`, definition);
    return response.data;
  },
  delete: async (id: number) => {
    await api.delete(`/custom-fields/${id}`);
  }
};
