import { ProductLiftClient, summarizePostDetail } from "../src/client.js";

async function main(): Promise<void> {
	const client = new ProductLiftClient();

	console.log( "=== list statuses ===" );
	const statuses = await client.listStatuses();
	console.log( `Found ${ statuses.length } statuses` );
	console.log( statuses.slice( 0, 5 ).map( ( s ) => `${ s.id }: ${ s.name }` ).join( "\n" ) );

	console.log( "\n=== search 2FA ===" );
	const search = await client.searchWishes( {
		query: "2FA",
		maxResults: 5,
		searchIn: "title",
	} );
	console.log( `Matches: ${ search.matches.length }` );
	for ( const post of search.matches ) {
		console.log( `- ${ post.id }: ${ post.title } [${ post.status.name }]` );
	}

	if ( search.matches[0] ) {
		console.log( "\n=== get wish ===" );
		const post = await client.getPost( search.matches[0].id );
		console.log( summarizePostDetail( post ).slice( 0, 500 ) );
	}

	console.log( "\nRead-only verification passed." );
}

main().catch( ( error ) => {
	console.error( error );
	process.exit( 1 );
} );
