import { apiEndpoints } from "@/lib/api/endpoints";
import { fetchWithAuth } from "@/lib/auth/client";
import type { LoginResponse, SessionsResponse, SuccessMessage } from "@/types/api";

export async function loginDashboardUser(email: string, password: string) {
  return fetchWithAuth<LoginResponse>(apiEndpoints.auth.login, {
    method: "POST",
    body: JSON.stringify({ email, password }),
  });
}

export async function refreshDashboardUser(refreshToken: string) {
  return fetchWithAuth<LoginResponse>(apiEndpoints.auth.refresh, {
    method: "POST",
    body: JSON.stringify({ refreshToken }),
  });
}

export async function logoutDashboardUser(refreshToken: string) {
  return fetchWithAuth<SuccessMessage>(apiEndpoints.auth.logout, {
    method: "POST",
    body: JSON.stringify({ refreshToken }),
  });
}

export async function listSuperAdminSessions() {
  return fetchWithAuth<SessionsResponse>(apiEndpoints.auth.superAdminSessions);
}

export async function revokeSuperAdminSession(sessionId: string) {
  return fetchWithAuth<SuccessMessage>(apiEndpoints.auth.revokeSuperAdminSession(sessionId), {
    method: "POST",
  });
}
