35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { AutomationSession } from '../../domain/entities/AutomationSession';
|
|
import { HostedSessionConfig } from '../../domain/entities/HostedSessionConfig';
|
|
import { AutomationEnginePort } from '../ports/AutomationEnginePort';
|
|
import type { IBrowserAutomation } from '../ports/ScreenAutomationPort';
|
|
import { SessionRepositoryPort } from '../ports/SessionRepositoryPort';
|
|
import type { SessionDTO } from '../dto/SessionDTO';
|
|
|
|
export class StartAutomationSessionUseCase {
|
|
constructor(
|
|
private readonly automationEngine: AutomationEnginePort,
|
|
private readonly browserAutomation: IBrowserAutomation,
|
|
private readonly sessionRepository: SessionRepositoryPort
|
|
) {}
|
|
|
|
async execute(config: HostedSessionConfig): Promise<SessionDTO> {
|
|
const session = AutomationSession.create(config);
|
|
|
|
const validationResult = await this.automationEngine.validateConfiguration(config);
|
|
if (!validationResult.isValid) {
|
|
throw new Error(validationResult.error);
|
|
}
|
|
|
|
await this.sessionRepository.save(session);
|
|
|
|
return {
|
|
sessionId: session.id,
|
|
state: session.state.value,
|
|
currentStep: session.currentStep.value,
|
|
config: session.config,
|
|
startedAt: session.startedAt,
|
|
completedAt: session.completedAt,
|
|
errorMessage: session.errorMessage,
|
|
};
|
|
}
|
|
} |