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

/**
 * desktop_op 操作审计日志
 * 每个 task 终态(成功 / 失败 / abort / queue-overflow)写一条
 */
@Entity('desktop_op_action_log')
export class DesktopOpActionLogEntity extends BaseEntity {
  @Index()
  @Column({ comment: '任务 id', length: 64 })
  taskId: string;

  @Index()
  @Column({ comment: '应用 id(weixin / excel / ...)', length: 32 })
  appId: string;

  @Column({ comment: 'task.target 完整 JSON', type: 'json', nullable: true })
  targetJson: any;

  @Column({ comment: '动作类型,如 send-text', length: 32 })
  actionType: string;

  @Column({ comment: '参数预览(text 等截断 200 字)', length: 200, nullable: true })
  paramsPreview: string;

  @Column({ comment: '最终文本全文(微信场景含水印)', type: 'text', nullable: true })
  finalText: string;

  @Index()
  @Column({ comment: '关联 NetaClawAgentChannel id(微信场景)', nullable: true, type: 'bigint' })
  channelId: number | null;

  @Column({ comment: '关联群名 / 对话名', length: 128, nullable: true })
  roomName: string;

  @Column({ comment: 'modelChannel id', nullable: true, type: 'bigint' })
  modelChannelId: number | null;

  @Column({ comment: 'VLM 调用次数', default: 0 })
  modelCalls: number;

  @Column({ comment: 'ActionStep 步数', default: 0 })
  steps: number;

  @Column({ comment: '耗时 ms', default: 0 })
  durationMs: number;

  @Index()
  @Column({ comment: '状态 success / 各错误 token', length: 32 })
  status: string;

  @Column({ comment: '错误消息', type: 'text', nullable: true })
  error: string;

  @Column({ comment: 'abort 原因', length: 64, nullable: true })
  abortedReason: string;
}
