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

@Entity('alert_rules')
export class AlertRule {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

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

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

  @Column({ type: 'varchar', length: 30 })
  metricType!: 'cpu' | 'memory' | 'disk' | 'network' | 'custom';

  @Column({ type: 'jsonb' })
  condition!: {
    operator: '>' | '<' | '==' | '>=';
    threshold: number;
    durationSeconds: number;
  };

  @Column({ type: 'varchar', length: 20 })
  severity!: 'info' | 'warning' | 'critical' | 'fatal';

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

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

  @Column({ type: 'boolean', default: true })
  isActive!: boolean;

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