"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorFactory = exports.AuthenticationError = exports.DataError = exports.TestError = void 0;
const logger_1 = require("./logger");
class TestError extends Error {
    constructor(message, role, context) {
        super(message);
        this.name = 'TestError';
        this.role = role;
        this.context = context;
        logger_1.logger.error(this.format(), 'TestError');
    }
    format() {
        const parts = [this.message];
        if (this.role) {
            parts.push(`Роль: ${this.role}`);
        }
        if (this.context && Object.keys(this.context).length > 0) {
            const contextStr = Object.entries(this.context)
                .map(([key, value]) => `${key}=${String(value)}`)
                .join(', ');
            parts.push(`Контекст: ${contextStr}`);
        }
        return parts.join(' | ');
    }
}
exports.TestError = TestError;
class DataError extends TestError {
    constructor(message, operation, role, dataKey, dataValue, context) {
        super(message, role, context);
        this.name = 'DataError';
        this.operation = operation;
        this.dataKey = dataKey;
        this.dataValue = dataValue;
    }
    format() {
        const parts = [super.format(), `Операция: ${this.operation}`];
        if (this.dataKey) {
            parts.push(`Ключ данных: ${this.dataKey}`);
        }
        if (this.dataValue !== undefined) {
            parts.push(`Значение: ${String(this.dataValue)}`);
        }
        return parts.join(' | ');
    }
}
exports.DataError = DataError;
class AuthenticationError extends TestError {
    constructor(message, authType, role, credentials, context) {
        super(message, role, context);
        this.name = 'AuthenticationError';
        this.authType = authType;
        this.credentials = credentials;
    }
    format() {
        const parts = [super.format(), `Тип авторизации: ${this.authType}`];
        if (this.credentials && Object.keys(this.credentials).length > 0) {
            const safeCredentials = { ...this.credentials };
            if (safeCredentials.password) {
                safeCredentials.password = '***';
            }
            parts.push(`Учетные данные: ${JSON.stringify(safeCredentials)}`);
        }
        return parts.join(' | ');
    }
}
exports.AuthenticationError = AuthenticationError;
class ErrorFactory {
    static data(operation, message, role, dataKey, dataValue, context) {
        return new DataError(message, operation, role, dataKey, dataValue, context);
    }
    static authentication(authType, message, role, credentials, context) {
        return new AuthenticationError(message, authType, role, credentials, context);
    }
}
exports.ErrorFactory = ErrorFactory;
