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

export interface JobStatusData {
    id: number;
    is_active: string;
    created_at:string,
    job_status_translation:{
        job_status_xid: number,
        title:string,
        language_xid:number
    }[],
}

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: JobStatusData[];
    };
}

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


export type PostJobStatus = {
 title: string
};


export const managePosts = createApi({
    reducerPath: "managePosts",
    baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling
    endpoints: (builder) => ({
        // createJobStatusPost: builder.mutation<PostJobStatus, Partial<PostJobStatus>>({
        //     query: (data) => ({
        //         url: "/job-status-store",
        //         method: "POST",
        //         body: data,
        //     }),
        // }),
        // 🔹 GET: Fetch all posts
        getManagePosts: builder.query<ApiResponse, number>({
            query: (page = 1) => `/manage-post-list?page=${page}`,
        }),

        postStatusToggle: builder.mutation({
            query: ({ id, is_active }) => ({
                url: `/manage-post-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 {
    useGetManagePostsQuery,
    usePostStatusToggleMutation,
    // useDeleteFaqPostMutation
} = managePosts;