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

@Entity('command_records')
export class CommandRecord {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

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

  @Column({ type: 'uuid' })
  sessionId!: string;

  @Column({ type: 'text' })
  command!: string;

  @Column({ type: 'smallint', default: 0 })
  riskLevel!: 0 | 1 | 2 | 3;

  @Column({ type: 'varchar', length: 20 })
  status!: 'executed' | 'blocked' | 'approved' | 'rejected';

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

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

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

  @Column({ type: 'timestamptz', default: () => 'NOW()' })
  executedAt!: Date;

  @Column({ type: 'int', nullable: true })
  durationMs?: number;
}
