/**
 * Reject Agent Run Use Case
 *
 * Rejects a paused agent run (waiting_approval status) and
 * marks it as cancelled with the rejection reason.
 */
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); }
};
import { injectable, inject } from 'tsyringe';
import { AgentRunStatus } from '../../../domain/generated/output.js';
let RejectAgentRunUseCase = class RejectAgentRunUseCase {
    agentRunRepository;
    constructor(agentRunRepository) {
        this.agentRunRepository = agentRunRepository;
    }
    async execute(id, reason) {
        const run = await this.agentRunRepository.findById(id);
        if (!run) {
            return { rejected: false, reason: 'Agent run not found' };
        }
        if (run.status !== AgentRunStatus.waitingApproval) {
            return {
                rejected: false,
                reason: `Agent run is not waiting for approval (status: ${run.status})`,
            };
        }
        const now = new Date();
        await this.agentRunRepository.updateStatus(id, AgentRunStatus.cancelled, {
            approvalStatus: 'rejected',
            error: reason ?? 'Rejected by user',
            completedAt: now,
            updatedAt: now,
        });
        return { rejected: true, reason: 'Rejected and cancelled' };
    }
};
RejectAgentRunUseCase = __decorate([
    injectable(),
    __param(0, inject('IAgentRunRepository')),
    __metadata("design:paramtypes", [Object])
], RejectAgentRunUseCase);
export { RejectAgentRunUseCase };
