import { createApi } from "@reduxjs/toolkit/query/react";
import { baseQueryWithReauth } from "./apiSlice";


export interface Terms {
  id: number,
  language_master_xid: number,
  content: string,
  is_active: boolean,
  terms_cond_language: {
    id: number,
    language_name: string,
    language_code: string,
  }
}

export const termsAndCondition = createApi({
  reducerPath: "termsAndCondition",
  baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling
  endpoints: (builder) => ({
    getTerms: builder.query<{ data: Terms[] }, void>({ query: () => "/term-and-condition" }),

    updateTerms: builder.mutation({
      query: (updatedData) => ({
        url: "/term-and-condition/update", // ✅ Updated URL
        method: "POST",
        body: updatedData,
      }),
    }),




  }),
});

export const {
  useGetTermsQuery,
  useUpdateTermsMutation,
} = termsAndCondition;
