import { logger } from '../logger.js';
export class DbSeeder {
    referenceResolver;
    constructor(referenceResolver) {
        this.referenceResolver = referenceResolver;
    }
    /**
     * Check if DB is empty and seed if configured.
     * Called once during ConfigManagers service startup, after initialize().
     */
    async seedIfEmpty(seedOnEmpty, seedData) {
        if (!seedOnEmpty)
            return;
        const existingProfiles = this.referenceResolver.listProfiles();
        const existingTargets = this.referenceResolver.listTargets();
        if (existingProfiles.length > 0 || existingTargets.length > 0) {
            logger.log('info', 'DB already contains profiles/targets, skipping seed');
            return;
        }
        logger.log('info', 'Seeding database with initial profiles and targets...');
        const profilesToSeed = seedData?.profiles ?? DEFAULT_PROFILES;
        const targetsToSeed = seedData?.targets ?? DEFAULT_TARGETS;
        for (const p of profilesToSeed) {
            await this.referenceResolver.createProfile({
                name: p.name,
                description: p.description,
                security: p.security,
                extendsProfiles: p.extendsProfiles,
                createdBy: 'system-seed',
            });
        }
        for (const t of targetsToSeed) {
            await this.referenceResolver.createTarget({
                name: t.name,
                description: t.description,
                host: t.host,
                port: t.port,
                createdBy: 'system-seed',
            });
        }
        logger.log('info', `Seeded ${profilesToSeed.length} profile(s) and ${targetsToSeed.length} target(s)`);
    }
}
const DEFAULT_PROFILES = [
    {
        name: 'TRUSTED NETWORKS',
        description: 'Trusted office, VPN, localhost, and private-network sources with high connection allowance',
        security: {
            ipAllowList: ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', '127.0.0.1', '::1'],
            maxConnections: 5000,
        },
    },
    {
        name: 'AI CRAWLERS',
        description: 'Add verified crawler CIDRs before assigning this profile in a source policy',
        security: {
            ipAllowList: [],
            rateLimit: {
                enabled: true,
                maxRequests: 30,
                window: 60,
                keyBy: 'ip',
            },
        },
    },
    {
        name: 'PUBLIC',
        description: 'Public fallback source profile with per-IP request limiting',
        security: {
            ipAllowList: ['*'],
            rateLimit: {
                enabled: true,
                maxRequests: 120,
                window: 60,
                keyBy: 'ip',
            },
        },
    },
    {
        name: 'STANDARD',
        description: 'Standard internal access with common private subnets',
        security: {
            ipAllowList: ['192.168.0.0/16', '10.0.0.0/8', '127.0.0.1', '::1'],
            maxConnections: 1000,
        },
    },
];
const DEFAULT_TARGETS = [
    {
        name: 'LOCALHOST',
        description: 'Local machine on port 443',
        host: '127.0.0.1',
        port: 443,
    },
];
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5kYi1zZWVkZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi90cy9jb25maWcvY2xhc3Nlcy5kYi1zZWVkZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLE1BQU0sRUFBRSxNQUFNLGNBQWMsQ0FBQztBQW1CdEMsTUFBTSxPQUFPLFFBQVE7SUFDQztJQUFwQixZQUFvQixpQkFBb0M7UUFBcEMsc0JBQWlCLEdBQWpCLGlCQUFpQixDQUFtQjtJQUFHLENBQUM7SUFFNUQ7OztPQUdHO0lBQ0ksS0FBSyxDQUFDLFdBQVcsQ0FDdEIsV0FBcUIsRUFDckIsUUFBb0I7UUFFcEIsSUFBSSxDQUFDLFdBQVc7WUFBRSxPQUFPO1FBRXpCLE1BQU0sZ0JBQWdCLEdBQUcsSUFBSSxDQUFDLGlCQUFpQixDQUFDLFlBQVksRUFBRSxDQUFDO1FBQy9ELE1BQU0sZUFBZSxHQUFHLElBQUksQ0FBQyxpQkFBaUIsQ0FBQyxXQUFXLEVBQUUsQ0FBQztRQUU3RCxJQUFJLGdCQUFnQixDQUFDLE1BQU0sR0FBRyxDQUFDLElBQUksZUFBZSxDQUFDLE1BQU0sR0FBRyxDQUFDLEVBQUUsQ0FBQztZQUM5RCxNQUFNLENBQUMsR0FBRyxDQUFDLE1BQU0sRUFBRSxxREFBcUQsQ0FBQyxDQUFDO1lBQzFFLE9BQU87UUFDVCxDQUFDO1FBRUQsTUFBTSxDQUFDLEdBQUcsQ0FBQyxNQUFNLEVBQ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