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

@Entity('ops_tasks')
export class OpsTask {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

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

  @Column({ type: 'varchar', length: 30 })
  type!: 'inspection' | 'deployment' | 'rollback' | 'scaling' | 'recovery';

  @Column({ type: 'varchar', length: 200 })
  title!: string;

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

  @Column({ type: 'varchar', length: 20, default: 'pending' })
  status!: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';

  @Column({ type: 'smallint', default: 1 })
  priority!: number;

  @Column({ type: 'uuid', array: true })
  targetServers!: string[];

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

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

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

  @CreateDateColumn({ type: 'timestamptz' })
  createdAt!: Date;

  @Column({ type: 'timestamptz', nullable: true })
  completedAt?: Date;

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