import { WorkOS } from '@workos-inc/node';

export const workos = new WorkOS(process.env.WORKOS_API_KEY!);

export const clientId = process.env.WORKOS_CLIENT_ID!;

export type OAuthProvider = 'GoogleOAuth' | 'AppleOAuth' | 'GitHubOAuth';

export function getAuthorizationUrl(provider: OAuthProvider) {
  return workos.userManagement.getAuthorizationUrl({
    provider,
    clientId,
    redirectUri: process.env.WORKOS_REDIRECT_URI!,
  });
}

// Get AuthKit hosted login URL (for email/password and phone)
// Note: We manually construct this URL with provider=authkit
export function getAuthKitUrl() {
  const params = new URLSearchParams({
    client_id: clientId,
    redirect_uri: process.env.WORKOS_REDIRECT_URI!,
    response_type: 'code',
    provider: 'authkit',
  });

  return `https://api.workos.com/user_management/authorize?${params.toString()}`;
}
