"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 networks_seed_data_1 = require("./networks.seed-data");
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);
    let created = 0;
    let skipped = 0;
    for (const entry of networks_seed_data_1.allNetworks) {
        const existing = await repositories.networkRepository.findByName(entry.name);
        if (existing) {
            services.logger.info('Network already exists, skipping', { name: entry.name });
            skipped++;
            continue;
        }
        await useCases.createNetwork.execute({
            name: entry.name,
            code: entry.symbol,
            addressType: (0, networks_seed_data_1.getNetworkAddressType)(entry),
            thumbnail: (0, networks_seed_data_1.getNetworkThumbnail)(entry),
            explorer: (0, networks_seed_data_1.getNetworkExplorer)(entry),
            chainId: entry.chainId,
            status: 'active',
        });
        services.logger.info('Network created', { name: entry.name });
        created++;
    }
    services.logger.info('Network seeding complete', { created, skipped, total: networks_seed_data_1.allNetworks.length });
    await redis_client_1.redisClient.quit();
    process.exit(0);
};
run().catch((error) => {
    // eslint-disable-next-line no-console
    console.error('Network seeding failed', error);
    process.exit(1);
});
//# sourceMappingURL=seed-networks.js.map