import { LoginResult } from '#services/auth';

/**
 * Build the standard response body for mobile/Zalo Bearer-token logins.
 * Tokens are returned in the body (not cookies) for mobile clients.
 */
export function buildMobileLoginResponse(loginResult: LoginResult) {
	return {
		user: {
			id: loginResult.user.id,
			email: loginResult.user.email,
			username: loginResult.user.username,
			first_name: loginResult.user.first_name,
			last_name: loginResult.user.last_name,
			roles: loginResult.roles,
			permissions: loginResult.permissions,
			status: loginResult.user.status,
			last_login_at: (loginResult.user as any).user_auth?.last_login_at,
			resident_id: loginResult.residentId ?? null,
		},
		access_token: loginResult.accessToken,
		refresh_token: loginResult.refreshToken,
		token_type: 'Bearer',
	};
}
