import { Entity, Column, PrimaryColumn, Index, CreateDateColumn } from 'typeorm';

@Entity('audit_logs')
@Index(['organization_id', 'timestamp'])
@Index(['user_id', 'timestamp'])
@Index(['resource_type', 'resource_id'])
@Index(['action'])
export class AuditLogOrmEntity {
  @PrimaryColumn('uuid')
  id: string;

  @Column({
    type: 'varchar',
    length: 100,
  })
  action: string;

  @Column({
    type: 'varchar',
    length: 20,
  })
  status: string;

  @Column('uuid')
  @Index()
  user_id: string;

  @Column({
    type: 'varchar',
    length: 255,
  })
  user_email: string;

  @Column('uuid')
  @Index()
  organization_id: string;

  @Column({
    type: 'varchar',
    length: 100,
    nullable: true,
  })
  resource_type?: string;

  @Column({
    type: 'uuid',
    nullable: true,
  })
  resource_id?: string;

  @Column({
    type: 'varchar',
    length: 500,
    nullable: true,
  })
  resource_name?: string;

  @Column({
    type: 'jsonb',
    nullable: true,
  })
  metadata?: Record<string, any>;

  @Column({
    type: 'varchar',
    length: 45,
    nullable: true,
  })
  ip_address?: string;

  @Column({
    type: 'text',
    nullable: true,
  })
  user_agent?: string;

  @Column({
    type: 'text',
    nullable: true,
  })
  error_message?: string;

  @CreateDateColumn({
    type: 'timestamp with time zone',
  })
  @Index()
  timestamp: Date;
}
