import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { ErrorLog } from 'src/entities/error-log.entity';
import { Repository } from 'typeorm';

@Injectable()
export class ErrorLogService {
    constructor(
        @InjectRepository(ErrorLog)
        private ErrorLog: Repository<ErrorLog>,
    ) { }

    async logError(module: string, errorType: string, message: string, context?: any) {
        try {
            await this.ErrorLog.save({
                module,
                errorType,
                message,
                context,
            });
        } catch (saveError) {
            console.error('Failed to save error log to DB:', saveError);
        }
    }
}