"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StartCrawlCommand = void 0; const Result_1 = require("../../../../shared/domain/Result"); const Url_1 = require("../../domain/value-objects/Url"); const CrawlSession_1 = require("../../domain/entities/CrawlSession"); class StartCrawlCommand { constructor(repository, eventBus) { this.repository = repository; this.eventBus = eventBus; } async execute(request) { const urlResult = Url_1.Url.create(request.url); if (!urlResult.ok) { return (0, Result_1.Err)(urlResult.error); } const sessionResult = CrawlSession_1.CrawlSession.create({ url: request.url, seed: request.seed, maxStates: request.maxStates, config: request.config, }); if (!sessionResult.ok) { return (0, Result_1.Err)(sessionResult.error); } const session = sessionResult.value; await this.repository.save(session); const events = session.domainEvents; for (const event of events) { await this.eventBus.publish(event); } session.clearEvents(); return (0, Result_1.Ok)({ sessionId: session.id.toString() }); } } exports.StartCrawlCommand = StartCrawlCommand;