/**
 * Authentication API functions.
 *
 * Wraps calls to POST /api/auth/login and POST /api/auth/logout
 * using the central typed fetch client.
 */

import { api } from "./client";
import { ENDPOINTS } from "./endpoints";
import type { LoginResponse, LogoutResponse } from "../types/auth";

/**
 * Authenticate with the master password.
 *
 * @param password - The master password entered by the user.
 * @returns The login response containing the session token.
 */
export async function login(password: string): Promise<LoginResponse> {
  return api.post<LoginResponse>(ENDPOINTS.authLogin, { password });
}

/**
 * Log out and invalidate the current session.
 *
 * @returns The logout confirmation message.
 */
export async function logout(): Promise<LogoutResponse> {
  return api.post<LogoutResponse>(ENDPOINTS.authLogout, {});
}
