import { Oauth2Application } from "../api/oauth2-api.ts";

export function prettyOauth2Application(app: Oauth2Application): string {
    return (`ID: ${app.id}
    Name: ${app.name}
    Redirect URIs: ${app.redirect_uris.join(", ")}
    Client ID: ${app.client_id}
    Confidential Client: ${app.confidential_client ? "Yes" : "No"}
    Created: ${new Date(app.created).toLocaleString()}`);
}

export async function saveSecretKeys(path: string, clientId: string, clientSecret: string): Promise<void> {
    const secretKey = `FORGEJO_CLIENT_KEY=${clientId}\nFORGEJO_SECRET_KEY=${clientSecret}`;
    await Deno.writeTextFile(path, secretKey, { append: true, create: true });
    console.log("OAuth2 secret keys saved successfully!");
}