{"version":3,"file":"useContactPoints.mjs","sources":["../../../../../../src/grafana/contactPoints/hooks/v0alpha1/useContactPoints.tsx"],"sourcesContent":["import {\n  type TypedUseMutationResult,\n  type TypedUseQueryHookResult,\n  fetchBaseQuery,\n} from '@reduxjs/toolkit/query/react';\nimport { OverrideProperties } from 'type-fest';\n\nimport {\n  CreateReceiverApiArg,\n  ListReceiverApiArg,\n  generatedAPI as notificationsAPIv0alpha1,\n} from '@grafana/api-clients/rtkq/notifications.alerting/v0alpha1';\n\nimport type { ContactPoint, EnhancedListReceiverApiResponse } from '../../../api/notifications/v0alpha1/types';\n\n// this is a workaround for the fact that the generated types are not narrow enough\ntype ListContactPointsHookResult = TypedUseQueryHookResult<\n  EnhancedListReceiverApiResponse,\n  ListReceiverApiArg,\n  ReturnType<typeof fetchBaseQuery>\n>;\n\n// Type for the options that can be passed to the hook\n// Based on the pattern used for mutation options in this file\ntype ListContactPointsQueryArgs = Parameters<\n  typeof notificationsAPIv0alpha1.endpoints.listReceiver.useQuery<ListContactPointsHookResult>\n>[0];\n\ntype ListContactPointsQueryOptions = Parameters<\n  typeof notificationsAPIv0alpha1.endpoints.listReceiver.useQuery<ListContactPointsHookResult>\n>[1];\n\n/**\n * useListContactPoints is a hook that fetches a list of contact points\n *\n * This function wraps the notificationsAPIv0alpha1.useListReceiverQuery with proper typing\n * to ensure that the returned ContactPoints are correctly typed in the data.items array.\n *\n * It automatically uses the configured namespace for the query.\n *\n * @param queryOptions - Optional query options that will be passed to the underlying useListReceiverQuery hook.\n *                      These options can include refetchOnFocus, refetchOnMountOrArgChange, skip, etc.\n */\nexport function useListContactPoints(\n  queryArgs: ListContactPointsQueryArgs = {},\n  queryOptions: ListContactPointsQueryOptions = {}\n): ListContactPointsHookResult {\n  return notificationsAPIv0alpha1.useListReceiverQuery<ListContactPointsHookResult>(queryArgs, queryOptions);\n}\n\n// type narrowing mutations requires us to define a few helper types\ntype CreateContactPointArgs = OverrideProperties<\n  CreateReceiverApiArg,\n  { receiver: Omit<ContactPoint, 'status' | 'metadata'> }\n>;\n\ntype CreateContactPointMutation = TypedUseMutationResult<\n  ContactPoint,\n  CreateContactPointArgs,\n  ReturnType<typeof fetchBaseQuery>\n>;\n\ntype UseCreateContactPointOptions = Parameters<\n  typeof notificationsAPIv0alpha1.endpoints.createReceiver.useMutation<CreateContactPointMutation>\n>[0];\n\n/**\n * useCreateContactPoint is a hook that creates a new contact point with one or more integrations\n *\n * This function wraps the notificationsAPI.useCreateReceiverMutation with proper typing\n * to ensure that the payload supports type narrowing.\n */\nexport function useCreateContactPoint(\n  options?: UseCreateContactPointOptions\n): readonly [\n  (\n    args: CreateContactPointArgs\n  ) => ReturnType<ReturnType<typeof notificationsAPIv0alpha1.endpoints.createReceiver.useMutation>[0]>,\n  ReturnType<typeof notificationsAPIv0alpha1.endpoints.createReceiver.useMutation<CreateContactPointMutation>>[1],\n] {\n  const [updateFn, result] =\n    notificationsAPIv0alpha1.endpoints.createReceiver.useMutation<CreateContactPointMutation>(options);\n\n  const typedUpdateFn = (args: CreateContactPointArgs) => {\n    // @ts-expect-error this one is just impossible for me to figure out\n    const response = updateFn(args);\n    return response;\n  };\n\n  return [typedUpdateFn, result] as const;\n}\n"],"names":["notificationsAPIv0alpha1"],"mappings":";;;AA2CO,SAAS,qBACd,SAAA,GAAwC,EAAC,EACzC,YAAA,GAA8C,EAAC,EAClB;AAC7B,EAAA,OAAOA,YAAA,CAAyB,oBAAA,CAAkD,SAAA,EAAW,YAAY,CAAA;AAC3G;AAwBO,SAAS,sBACd,OAAA,EAMA;AACA,EAAA,MAAM,CAAC,UAAU,MAAM,CAAA,GACrBA,aAAyB,SAAA,CAAU,cAAA,CAAe,YAAwC,OAAO,CAAA;AAEnG,EAAA,MAAM,aAAA,GAAgB,CAAC,IAAA,KAAiC;AAEtD,IAAA,MAAM,QAAA,GAAW,SAAS,IAAI,CAAA;AAC9B,IAAA,OAAO,QAAA;AAAA,EACT,CAAA;AAEA,EAAA,OAAO,CAAC,eAAe,MAAM,CAAA;AAC/B;;;;"}