import { BaseModel } from './base.model';

export class ApplicationLog extends BaseModel {
  static tableName = 'application_logs';

  id!: string;
  level!: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
  module!: string;
  message!: string;
  context?: Record<string, any>;
  stackTrace?: string;
  userId?: string;
  correlationId?: string;
  ipAddress?: string;
  userAgent?: string;
  createdAt!: Date;

  static get jsonSchema() {
    return {
      type: 'object',
      required: ['level', 'module', 'message'],
      properties: {
        id: { type: 'string', format: 'uuid' },
        level: { type: 'string', enum: ['DEBUG', 'INFO', 'WARN', 'ERROR'] },
        module: { type: 'string', maxLength: 100 },
        message: { type: 'string' },
        context: { type: ['object', 'null'] },
        stackTrace: { type: ['string', 'null'] },
        userId: { type: ['string', 'null'], format: 'uuid' },
        correlationId: { type: ['string', 'null'], maxLength: 100 },
        ipAddress: { type: ['string', 'null'], maxLength: 45 },
        userAgent: { type: ['string', 'null'] },
        createdAt: { type: 'string', format: 'date-time' },
      },
    };
  }
}
