"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetUserByIdQueryHandler = void 0;
const UserMapper_1 = require("../../DTOs/Mappers/UserMapper");
const Logger_1 = require("../../Services/Logger");
class GetUserByIdQueryHandler {
    constructor(userRepo) {
        this.userRepo = userRepo;
    }
    async execute(query) {
        try {
            const user = await this.userRepo.findById(query.id);
            if (!user)
                return null;
            return UserMapper_1.UserMapper.toShortDto(user);
        }
        catch (error) {
            (0, Logger_1.logError)('GetUserByIdQueryHandler error', error instanceof Error ? error : new Error(String(error)));
            // Handle invalid ID format
            if (error instanceof Error && error.message.includes('invalid') && error.message.includes('uuid')) {
                return null; // Treat invalid UUID as not found
            }
            // Handle database errors
            if (error instanceof Error && error.message.includes('database')) {
                throw new Error('Database connection error');
            }
            // Generic error for other cases
            throw new Error('Failed to retrieve user');
        }
    }
}
exports.GetUserByIdQueryHandler = GetUserByIdQueryHandler;
//# sourceMappingURL=GetUserByIdQueryHandler.js.map