import type { SeamHttpApiError } from '@seamapi/http/connect' import { useSeamClient } from '@seamapi/react-query' import type { DeviceModel, RouteRequestParams, RouteResponse, } from '@seamapi/types/devicedb' import { useQuery } from '@tanstack/react-query' import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js' export type UseDeviceModelParams = DeviceModelsGetParams export type UseDeviceModelData = DeviceModel | null export function useDeviceModel( params: UseDeviceModelParams ): UseSeamQueryResultLegacy<'deviceModel', UseDeviceModelData> { const { client: seam } = useSeamClient() const { data, ...rest } = useQuery({ enabled: seam != null, queryKey: ['internal', 'device_models', 'get', params], queryFn: async () => { if (seam == null) return null const { data: { device_model: deviceModel }, } = await seam.client.get( '/internal/devicedb/v1/device_models/get', { params } ) // UPSTREAM: Response type does not match DeviceModel. return deviceModel as DeviceModel }, }) return { ...rest, deviceModel: data, } } type DeviceModelsGetParams = RouteRequestParams<'/v1/device_models/get'> type DeviceModelsGetResponse = RouteResponse<'/v1/device_models/get'>