import { createApi, fetchBaseQuery} from "@reduxjs/toolkit/query/react";

export interface Card {
	id: number;
	front: string;
	back: string;
	hint?: string;
	deck_id: number;
}
export interface CardDeck {
	id: number;
	title: string;
	description: string
	cards: Card[];
}

export const cardDeckApiSlice = createApi({
	reducerPath: 'carddeck',
	baseQuery: fetchBaseQuery({
		baseUrl: '/api/v1/'
	}),
	endpoints(builder) {
		return {
			fetchCardDecks: builder.query<CardDeck[], string>({
				query: (_) => "carddeck"
			}),
			fetchCardDeckById: builder.query<CardDeck, number>({
				query: (id) => `carddeck/${id}`
			})
		}
	}
})

export const { useFetchCardDecksQuery, useFetchCardDeckByIdQuery } = cardDeckApiSlice;
