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

export class BlockchainEvent extends BaseModel {
  static tableName = 'blockchain_events';

  id!: string;
  txHash!: string;
  eventName!: string;
  contractAddress!: string;
  blockNumber!: number;
  logIndex!: number;
  args!: Record<string, any>;
  decodedArgs?: Record<string, any>;
  relatedEntityType?: string;
  relatedEntityId?: string;
  createdAt!: Date;

  static get jsonSchema() {
    return {
      type: 'object',
      required: ['txHash', 'eventName', 'contractAddress', 'blockNumber', 'logIndex', 'args'],
      properties: {
        id: { type: 'string', format: 'uuid' },
        txHash: { type: 'string', maxLength: 66 },
        eventName: { type: 'string', maxLength: 100 },
        contractAddress: { type: 'string', maxLength: 42 },
        blockNumber: { type: 'integer' },
        logIndex: { type: 'integer' },
        args: { type: 'object' },
        decodedArgs: { type: ['object', 'null'] },
        relatedEntityType: { type: ['string', 'null'], maxLength: 50 },
        relatedEntityId: { type: ['string', 'null'], format: 'uuid' },
        createdAt: { type: 'string', format: 'date-time' },
      },
    };
  }
}
