"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("dotenv/config");
require("reflect-metadata");
const data_source_1 = require("../infrastructure/persistence/data-source");
const redis_client_1 = require("../infrastructure/cache/redis-client");
const repositories_factory_1 = require("../main/factories/repositories.factory");
const services_factory_1 = require("../main/factories/services.factory");
const use_cases_factory_1 = require("../main/factories/use-cases.factory");
const seed_tokens_helper_1 = require("./seed-tokens.helper");
const run = async () => {
    await (0, data_source_1.initializeDatabase)();
    const repositories = (0, repositories_factory_1.createRepositories)();
    const services = (0, services_factory_1.createServices)(redis_client_1.redisClient);
    const useCases = (0, use_cases_factory_1.createUseCases)(repositories, services);
    const networks = await repositories.networkRepository.findAll();
    services.logger.info('Seeding tokens for all networks', { totalNetworks: networks.length });
    let totalCreated = 0;
    let totalSkipped = 0;
    let totalFetched = 0;
    for (const network of networks) {
        const existingTokens = await repositories.tokenRepository.findByNetworkId(network.id);
        if (existingTokens.length > 0) {
            services.logger.info('Network already has tokens, skipping', {
                network: network.name,
                existingTokens: existingTokens.length,
            });
            totalSkipped += existingTokens.length;
            continue;
        }
        try {
            const result = await (0, seed_tokens_helper_1.seedTokensForNetwork)(network, useCases, repositories.tokenRepository, services.coinMarketCapClient, services.logger);
            totalCreated += result.created;
            totalSkipped += result.skipped;
            totalFetched += result.fetched;
        }
        catch (error) {
            services.logger.error('Failed to seed tokens for network', { network: network.name, error });
        }
    }
    services.logger.info('Token seeding complete', {
        created: totalCreated,
        skipped: totalSkipped,
        fetched: totalFetched,
    });
    await redis_client_1.redisClient.quit();
    process.exit(0);
};
run().catch((error) => {
    // eslint-disable-next-line no-console
    console.error('Token seeding failed', error);
    process.exit(1);
});
//# sourceMappingURL=seed-tokens.js.map