"use strict";
/**
 * Example usage of the Polygon SDK
 *
 * Before running this example:
 * 1. Set your POLYGON_API_KEY and POLYGON_API_SECRET environment variables
 * 2. Update the problemId with a valid problem ID you have access to
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.main = main;
const polygon_1 = require("../polygon");
async function main() {
    // Initialize the SDK
    const sdk = new polygon_1.PolygonSDK({
        apiKey: process.env['POLYGON_API_KEY'] || '',
        apiSecret: process.env['POLYGON_API_SECRET'] || '',
    });
    try {
        // Example 1: List all your problems
        console.log('📋 Fetching your problems...');
        const problems = await sdk.listProblems({ showDeleted: false });
        console.log(`Found ${problems.length} problems`);
        if (problems.length > 0) {
            console.log('\nFirst 5 problems:');
            problems.slice(0, 5).forEach(p => {
                console.log(`  - ${p.name} (ID: ${p.id}, Owner: ${p.owner})`);
            });
        }
        // Example 2: Get problem information
        // Replace with a valid problem ID you have access to
        const problemId = 123456;
        console.log(`\n🔍 Fetching info for problem ${problemId}...`);
        const info = await sdk.getProblemInfo(problemId);
        console.log('Problem Info:', {
            timeLimit: `${info.timeLimit}ms`,
            memoryLimit: `${info.memoryLimit}MB`,
            interactive: info.interactive,
            inputFile: info.inputFile,
            outputFile: info.outputFile,
        });
        // Example 3: Get statements
        console.log('\n📄 Fetching statements...');
        const statements = await sdk.getStatements(problemId);
        const languages = Object.keys(statements);
        console.log(`Available languages: ${languages.join(', ')}`);
        if (languages.length > 0) {
            const firstLang = languages[0];
            console.log(`\nStatement in ${firstLang}:`);
            console.log(`  Name: ${statements[firstLang].name}`);
            console.log(`  Legend: ${statements[firstLang].legend.substring(0, 100)}...`);
        }
        // Example 4: Get solutions
        console.log('\n💻 Fetching solutions...');
        const solutions = await sdk.getSolutions(problemId);
        console.log(`Found ${solutions.length} solutions:`);
        solutions.forEach(sol => {
            console.log(`  - ${sol.name} (${sol.tag})`);
        });
        // Example 5: Get tests
        console.log('\n🧪 Fetching tests...');
        const tests = await sdk.getTests(problemId, 'tests', true);
        console.log(`Found ${tests.length} tests:`);
        tests.slice(0, 5).forEach(test => {
            const type = test.manual ? 'manual' : 'generated';
            const desc = test.description ? ` - ${test.description}` : '';
            console.log(`  Test ${test.index} (${type})${desc}`);
        });
        // Example 6: Get files
        console.log('\n📁 Fetching files...');
        const files = await sdk.getFiles(problemId);
        console.log(`Resource files: ${files.resourceFiles.length}`);
        console.log(`Source files: ${files.sourceFiles.length}`);
        console.log(`Aux files: ${files.auxFiles.length}`);
        if (files.sourceFiles.length > 0) {
            console.log('\nSource files:');
            files.sourceFiles.forEach(f => {
                console.log(`  - ${f.name} (${f.sourceType || 'unknown'})`);
            });
        }
        // Example 7: Get checker and validator
        console.log('\n✅ Fetching checker and validator...');
        const checker = await sdk.getChecker(problemId);
        const validator = await sdk.getValidator(problemId);
        console.log(`Checker: ${checker}`);
        console.log(`Validator: ${validator}`);
        // Example 8: Get tags
        console.log('\n🏷️  Fetching tags...');
        const tags = await sdk.viewTags(problemId);
        console.log(`Tags: ${tags.join(', ') || 'No tags'}`);
        console.log('\n✅ All examples completed successfully!');
    }
    catch (error) {
        if (error instanceof Error) {
            console.error('❌ Error:', error.message);
        }
        else {
            console.error('❌ Unknown error:', error);
        }
    }
}
// Run the examples
if (require.main === module) {
    void main();
}
//# sourceMappingURL=polygon-sdk-example.js.map