package at.procon.ted.service;

import at.procon.ted.model.entity.ProcurementDocument;
import at.procon.ted.model.entity.ProcessingLog;
import at.procon.ted.repository.ProcessingLogRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service for logging processing events.
 *
 * @author Martin.Schweitzer@procon.co.at and claude.ai
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class ProcessingLogService {

    private final ProcessingLogRepository logRepository;

    @Transactional
    public void logEvent(ProcurementDocument document, String documentHash, String eventType,
                        String eventStatus, String message, String errorDetails,
                        String sourceFilename, Integer durationMs) {
        ProcessingLog logEntry = ProcessingLog.builder()
                .document(document)
                .documentHash(documentHash)
                .eventType(eventType)
                .eventStatus(eventStatus)
                .message(message)
                .errorDetails(errorDetails)
                .sourceFilename(sourceFilename)
                .durationMs(durationMs)
                .build();

        logRepository.save(logEntry);
    }
}
