/**
 * 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 { PieceModelStructure } from '~/shared/types/inventory'
import type { Ref } from 'vue'

export interface PieceType extends EntityType {
  structure: PieceModelStructure | null
}

export function usePieceTypes() {
  const { types, loading, loadTypes, createType, updateType, deleteType } = useEntityTypes({
    category: 'PIECE',
    label: 'pièce',
  })

  return {
    pieceTypes: types as Ref<PieceType[]>,
    loadingPieceTypes: loading,
    loadPieceTypes: loadTypes,
    createPieceType: createType,
    updatePieceType: updateType,
    deletePieceType: deleteType,
    getPieceTypes: () => types.value as PieceType[],
    isPieceTypeLoading: () => loading.value,
  }
}
