import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn } from 'typeorm';

@Entity('audit_logs')
export class AuditLog {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id!: number;

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

  @Column({ type: 'varchar', length: 50 })
  actionType!: string;

  @Column({ type: 'varchar', length: 20 })
  actorType!: 'agent' | 'user' | 'system';

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

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

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

  @Column({ type: 'jsonb' })
  detail!: Record<string, unknown>;

  @Column({ type: 'inet', nullable: true })
  ipAddress?: string;

  @CreateDateColumn({ type: 'timestamptz' })
  createdAt!: Date;
}
