import { BaseEntity } from '../../base/entity/base.js';
import { Column, Entity, Index } from 'typeorm';

@Entity('netaclaw_data_source_query_audit')
export class NetaClawDataSourceQueryAuditEntity extends BaseEntity {
  @Index()
  @Column({ comment: '数据源ID' })
  dataSourceId: number;

  @Index()
  @Column({ comment: 'Agent ID', nullable: true })
  agentId: number | null;

  @Index()
  @Column({ comment: '用户ID', nullable: true })
  userId: number | null;

  @Column({ comment: '工具调用ID', length: 100, nullable: true })
  toolCallId: string | null;

  @Column({ comment: 'SQL哈希', length: 64 })
  sqlHash: string;

  @Column({ comment: 'SQL预览', type: 'text', nullable: true })
  sqlPreview: string | null;

  @Index()
  @Column({ comment: '执行状态', length: 20 })
  status: string;

  @Column({ comment: '拒绝原因', length: 100, nullable: true })
  rejectReason: string | null;

  @Column({ comment: '耗时毫秒', nullable: true })
  elapsedMs: number | null;

  @Column({ comment: '返回行数', nullable: true })
  rowCount: number | null;

  @Column({ comment: '错误码', length: 50, nullable: true })
  errorCode: string | null;
}
