const { Pool } = require('pg');
require('dotenv').config({ path: __dirname + '/../../.env' });

const pool = new Pool({
	host: process.env.DB_HOST || 'localhost',
	port: process.env.DB_PORT || 5432,
	database: process.env.DB_NAME || 'vietprodev_sso',
	user: process.env.DB_USER || 'postgres',
	password: process.env.DB_PASSWORD,
});

(async () => {
	const client = await pool.connect();
	try {
		const { rows } = await client.query(`
			SELECT client_id, app_code, name, redirect_uris, post_logout_redirect_uris,
			       grant_types, response_types, scopes, token_endpoint_auth_method,
			       require_pkce, status
			FROM clients
			ORDER BY app_code;
		`);
		console.log('Registered OIDC clients:');
		console.log(JSON.stringify(rows, null, 2));
	} catch (e) {
		console.error('Query failed:', e.message);
		process.exit(1);
	} finally {
		client.release();
		await pool.end();
	}
})();
