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

export interface WorkspaceData {
    id: number;
    en_name: string;
    is_active: string;
}

interface ApiResponse {
    status: string;
    status_code: number;
    message: string;
    data: {
        current_page: number,
        last_page: number,
        total: number,
        from: number,
        per_page: number,
        to: number,
        data: WorkspaceData[];
    };
}

export interface CountryEdit {
    status: string;
    status_code: number;
    message: string;
    data: WorkspaceData[];
}

export interface DropDown {
    status: string;
    status_code: number;
    message: string;
    data: {
        id: number;
        en_name: string;
    }[]
}

export type PostDepartment = {
    en_name: string;
};


export const workspaceMode = createApi({
    reducerPath: "workspaceMode",
    baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling
    endpoints: (builder) => ({
        createWorkspacePost: builder.mutation<PostDepartment, Partial<PostDepartment>>({
            query: (data) => ({
                url: "/workspace-create",
                method: "POST",
                body: data,
            }),
        }),
        // 🔹 GET: Fetch all posts
        getWorkSpaceMode: builder.query<ApiResponse, number>({
            query: (page = 1) => `/workspace-mode?page=${page}`,
        }),

        updateWorkSpace: builder.mutation({
            query: (updatedData) => ({
                url: "/workspace-update",
                method: "POST",
                body: updatedData,
            }),
        }),

        workspaceToggle: builder.mutation({
            query: ({ id, is_active }) => ({
                url: `/workspace-status`,
                method: "POST",
                body: { id, is_active },
            }),
        }),

        // deleteFaqPost: builder.mutation<{ status: string; message: string }, { id: number }>({
        //     query: ({ id }) => ({
        //         url: `/faq-delete`,
        //         method: "POST",
        //         body: { id },
        //     }),
        // }),

    }),
});

export const {
    useGetWorkSpaceModeQuery,
    useCreateWorkspacePostMutation,
    useUpdateWorkSpaceMutation,
    useWorkspaceToggleMutation,
    // useDeleteFaqPostMutation
} = workspaceMode;