import axiosInstance from "@/shared/services/axiosInstance";
import { withHeaders } from "./withHeaders";

export interface sessionParams {
  skip?: number;
  take?: number;
  orderBy?: string;
}
interface revokeSessionPayload {
  sessionIds: string[];
}

export const getMySessions = async (params: sessionParams): Promise<any> => {
  try {
    return await axiosInstance.get(
      "sessions/my-sessions",

      {
        params: {
          ...params,
        },
        headers: withHeaders(),
      }
    );
  } catch (error) {
    throw error;
  }
};

export const deleteSession = async (id: string): Promise<any> => {
  try {
    return await axiosInstance.delete(`sessions/revoke/${id}`, {
      headers: withHeaders(),
    });
  } catch (error) {
    throw error;
  }
};

export const deleteAllSession = async (
  payload: revokeSessionPayload
): Promise<any> => {
  try {
    return await axiosInstance.post(`sessions/bulk-revoke`, payload, {
      headers: withHeaders(),
    });
  } catch (error) {
    throw error;
  }
};
