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

/**
 * Agent 集群（Crew）
 */
@Entity('netaclaw_crew')
export class NetaClawCrewEntity extends BaseEntity {
  @Column({ comment: '集群唯一标识', length: 100, unique: true })
  name: string;

  @Column({ comment: '显示名称', length: 200 })
  label: string;

  @Column({ comment: '集群描述', type: 'text', nullable: true })
  description: string;

  @Column({ comment: '图标', length: 500, nullable: true })
  icon: string;

  @Index()
  @Column({ comment: '主 Agent ID', nullable: true })
  masterAgentId: number;

  @Column({ type: 'json', comment: '画布布局数据', nullable: true })
  canvasData: Record<string, unknown>;

  @Column({ type: 'json', comment: '触发配置', nullable: true })
  triggerConfig: {
    manual?: boolean;
    cron?: { enabled: boolean; expression: string; timezone: string };
    webhook?: { enabled: boolean; secret: string };
    api?: { enabled: boolean; apiKey: string };
  };

  @Column({ type: 'json', comment: '委派提示（从连线生成）', nullable: true })
  delegateHints: {
    hints: string;
    edges: Array<{ from: string; to: string; type: string; note?: string }>;
  };

  @Index()
  @Column({ comment: '状态: 0=草稿 1=已发布', default: 0 })
  status: number;

  @Column({ comment: '最大并发子 Agent 数', default: 3 })
  maxConcurrent: number;

  @Column({ comment: '单个子任务默认超时（秒）', default: 300 })
  taskTimeout: number;

  @Column({ type: 'json', comment: '全局重试策略', nullable: true })
  retryPolicy: { maxRetries: number; retryDelay: number };
}
