import { apiRequest } from "@/lib/queryClient";

export type AutoLoginStatus = {
  configured: boolean;
  last_refreshed_at: string | null;
  last_error: string | null;
};

export type AutoLoginSetupRequest = {
  zerodha_login_id: string;
  password: string;
  totp_secret: string;
};

export async function getAutoLoginStatus(): Promise<AutoLoginStatus> {
  const res = await apiRequest("GET", "/auto-login/status");
  return res.json();
}

export async function setupAutoLogin(data: AutoLoginSetupRequest): Promise<{ configured: boolean; message: string }> {
  const res = await apiRequest("POST", "/auto-login/setup", data);
  return res.json();
}

export async function removeAutoLogin(): Promise<{ configured: boolean; message: string }> {
  const res = await apiRequest("DELETE", "/auto-login/setup");
  return res.json();
}

export async function triggerAutoLogin(): Promise<{ success: boolean; message: string }> {
  const res = await apiRequest("POST", "/auto-login/trigger");
  return res.json();
}
