"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExecutionLogsService = void 0;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const typeorm_2 = require("typeorm");
const core_entities_1 = require("../core-entities");
let ExecutionLogsService = class ExecutionLogsService {
    constructor(executionLogsRepository, aiActionsRepository) {
        this.executionLogsRepository = executionLogsRepository;
        this.aiActionsRepository = aiActionsRepository;
    }
    async createLog(createExecutionLogDto) {
        const aiAction = await this.aiActionsRepository.findOneBy({
            id: createExecutionLogDto.action_id,
        });
        if (!aiAction) {
            throw new common_1.NotFoundException(`AIAction with ID "${createExecutionLogDto.action_id}" not found. Cannot create execution log.`);
        }
        const newLog = this.executionLogsRepository.create({
            ...createExecutionLogDto,
            aiAction: aiAction,
        });
        return this.executionLogsRepository.save(newLog);
    }
    async findAllByActionId(actionId) {
        const aiAction = await this.aiActionsRepository.findOneBy({
            id: actionId,
        });
        if (!aiAction) {
            throw new common_1.NotFoundException(`AIAction with ID "${actionId}" not found. Cannot retrieve execution logs.`);
        }
        return this.executionLogsRepository.find({
            where: { action_id: actionId },
            order: { created_at: 'ASC' },
        });
    }
};
exports.ExecutionLogsService = ExecutionLogsService;
exports.ExecutionLogsService = ExecutionLogsService = __decorate([
    (0, common_1.Injectable)(),
    __param(0, (0, typeorm_1.InjectRepository)(core_entities_1.ExecutionLog)),
    __param(1, (0, typeorm_1.InjectRepository)(core_entities_1.AIAction)),
    __metadata("design:paramtypes", [typeorm_2.Repository,
        typeorm_2.Repository])
], ExecutionLogsService);
//# sourceMappingURL=execution-logs.service.js.map