/**
 * Configure Agent Use Case
 *
 * Configures the AI coding agent for the Shep platform.
 * Validates agent availability before persisting configuration.
 *
 * Business Rules:
 * - Agent binary must be available on the system before configuring
 * - Settings must exist before updating (must initialize first)
 * - Token is optional and only included when provided
 * - Returns updated settings after persistence
 */
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';
/**
 * Use case for configuring the AI coding agent.
 *
 * Algorithm:
 * 1. Validate agent binary is available on the system
 * 2. Load current settings from repository
 * 3. Update agent configuration
 * 4. Persist updated settings
 * 5. Return updated settings
 */
let ConfigureAgentUseCase = class ConfigureAgentUseCase {
    settingsRepository;
    agentValidator;
    constructor(settingsRepository, agentValidator) {
        this.settingsRepository = settingsRepository;
        this.agentValidator = agentValidator;
    }
    /**
     * Execute the configure agent use case.
     *
     * @param input - Agent configuration input
     * @returns Updated Settings with new agent configuration
     * @throws Error if agent is not available or settings not initialized
     */
    async execute(input) {
        // 1. Validate agent is available
        const validation = await this.agentValidator.isAvailable(input.type);
        if (!validation.available) {
            throw new Error(`Agent "${input.type}" is not available: ${validation.error ?? 'binary not found'}`);
        }
        // 2. Load current settings
        const settings = await this.settingsRepository.load();
        if (!settings) {
            throw new Error('Settings not found. Please run initialization first.');
        }
        // 3. Update agent config
        const updatedSettings = {
            ...settings,
            agent: {
                type: input.type,
                authMethod: input.authMethod,
                ...(input.token !== undefined && { token: input.token }),
            },
            updatedAt: new Date(),
        };
        // 4. Persist
        await this.settingsRepository.update(updatedSettings);
        return updatedSettings;
    }
};
ConfigureAgentUseCase = __decorate([
    injectable(),
    __param(0, inject('ISettingsRepository')),
    __param(1, inject('IAgentValidator')),
    __metadata("design:paramtypes", [Object, Object])
], ConfigureAgentUseCase);
export { ConfigureAgentUseCase };
