"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SolidCoreErrorCodesProvider = void 0;
const common_1 = require("@nestjs/common");
const error_codes_provider_decorator_1 = require("../decorators/error-codes-provider.decorator");
let SolidCoreErrorCodesProvider = class SolidCoreErrorCodesProvider {
    name() {
        return 'SolidCoreErrorCodeProvider';
    }
    rules() {
        return [
            {
                code: 'solidx-mcp-server-unavailable',
                priority: 100,
                match: (txt) => txt.includes('all connection attempts failed') &&
                    txt.includes('unhandled errors in a taskgroup (1 sub-exception)'),
                meta: {
                    message: 'SolidX MCP server is unreachable. Please verify the MCP endpoint.',
                    httpStatus: 503,
                },
            },
            {
                code: 'solidx-db-duplicate-key',
                priority: 90,
                match: (txt) => txt.includes('unique constraint') || txt.includes('duplicate key'),
                meta: {
                    message: 'Duplicate key violation. A record with these values already exists.',
                    httpStatus: 409,
                },
            },
            {
                code: 'solidx-db-foreign-key-error',
                priority: 90,
                match: (txt) => txt.includes('violates foreign key'),
                meta: {
                    message: 'Foreign key constraint prevents this operation due to related records.',
                    httpStatus: 409,
                },
            },
            {
                code: 'solidx-unknown-error',
                priority: -1,
                match: (_txt) => true,
                meta: {
                    message: 'An unexpected error occurred.',
                    httpStatus: 500,
                },
            },
        ];
    }
    resolve(code) {
        const rule = this.rules().find((r) => r.code === code);
        return rule?.meta;
    }
};
exports.SolidCoreErrorCodesProvider = SolidCoreErrorCodesProvider;
exports.SolidCoreErrorCodesProvider = SolidCoreErrorCodesProvider = __decorate([
    (0, error_codes_provider_decorator_1.ErrorCodeProvider)(),
    (0, common_1.Injectable)()
], SolidCoreErrorCodesProvider);
//# sourceMappingURL=solid-core-error-codes-provider.service.js.map