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

/**
 * 集群运行记录
 */
@Entity('netaclaw_crew_run')
export class NetaClawCrewRunEntity extends BaseEntity {
  @Index()
  @Column({ comment: '集群 ID' })
  crewId: number;

  @Column({ comment: '触发方式', length: 20 })
  triggerType: string;

  @Column({ comment: '触发输入参数', type: 'text', nullable: true })
  triggerInput: string;

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

  @Column({ comment: '主 Agent 会话 ID', nullable: true })
  masterSessionId: number;

  @Column({ comment: '开始时间', type: 'datetime', nullable: true })
  startTime: Date;

  @Column({ comment: '结束时间', type: 'datetime', nullable: true })
  endTime: Date;

  @Column({ type: 'json', comment: '运行结果摘要', nullable: true })
  result: Record<string, unknown>;

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

  @Column({ type: 'json', comment: '升级暂停时保存的对话上下文', nullable: true })
  pausedState: unknown;

  @Column({ type: 'json', comment: '累计 token 消耗', nullable: true })
  tokenUsage: { inputTokens: number; outputTokens: number };
}
