import { baseApi } from './baseApi';

export interface Promocion {
  id: number;
  nombre: string;
  [key: string]: unknown;
}

export const promocionesApi = baseApi.injectEndpoints({
  endpoints: (builder) => ({
    getPromociones: builder.query<Promocion[], void>({
      query: () => 'promociones/',
      providesTags: (result) =>
        result
          ? [
              ...result.map(({ id }) => ({ type: 'Promociones' as const, id })),
              { type: 'Promociones' as const, id: 'LIST' },
            ]
          : [{ type: 'Promociones' as const, id: 'LIST' }],
    }),
  }),
  overrideExisting: false,
});

export const { useGetPromocionesQuery } = promocionesApi;
