/**
 * Backward-compatible wrapper around useEntityTypes.
 * Preserves the original API surface (renamed fields) so consumers need no changes.
 */
import { useEntityTypes, type EntityType } from './useEntityTypes'
import type { ComponentModelStructure } from '~/shared/types/inventory'
import type { Ref } from 'vue'

export interface ComponentType extends EntityType {
  structure: ComponentModelStructure | null
}

export function useComponentTypes() {
  const { types, loading, loadTypes, createType, updateType, deleteType } = useEntityTypes({
    category: 'COMPONENT',
    label: 'composant',
  })

  return {
    componentTypes: types as Ref<ComponentType[]>,
    loadingComponentTypes: loading,
    loadComponentTypes: loadTypes,
    createComponentType: createType,
    updateComponentType: updateType,
    deleteComponentType: deleteType,
    getComponentTypes: () => types.value as ComponentType[],
    isComponentTypeLoading: () => loading.value,
  }
}
