import {
  Column,
  CreateDateColumn,
  Entity,
  PrimaryColumn,
  UpdateDateColumn,
} from 'typeorm';
import { randomUUID } from 'crypto';

@Entity({ name: 'incident_case' })
export class IncidentCaseEntity {
  @PrimaryColumn({ type: 'varchar', length: 64 })
  id: string = randomUUID();

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

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

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

  @Column({ type: 'varchar', length: 16, default: 'open' })
  status!: 'open' | 'acknowledged' | 'resolved';

  @Column({ type: 'text' })
  summary!: string;

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

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

  @Column({ name: 'latest_target_id', type: 'varchar', length: 64, nullable: true })
  latestTargetId!: string | null;

  @Column({ name: 'latest_run_id', type: 'varchar', length: 64, nullable: true })
  latestRunId!: string | null;

  @Column({ name: 'latest_alert_ids_json', type: 'text', nullable: true })
  latestAlertIdsJson!: string | null;

  @Column({ name: 'source_summary_json', type: 'text', nullable: true })
  sourceSummaryJson!: string | null;

  @Column({ name: 'evidence_json', type: 'text', nullable: true })
  evidenceJson!: string | null;

  @Column({ name: 'diagnosis_json', type: 'text', nullable: true })
  diagnosisJson!: string | null;

  @Column({ name: 'recommendation_json', type: 'text', nullable: true })
  recommendationJson!: string | null;

  @Column({ name: 'first_detected_at', type: 'timestamp' })
  firstDetectedAt!: Date;

  @Column({ name: 'last_detected_at', type: 'timestamp' })
  lastDetectedAt!: Date;

  @Column({ name: 'occurrence_count', type: 'int', default: 1 })
  occurrenceCount!: number;

  @Column({ name: 'storm_score', type: 'int', default: 0 })
  stormScore!: number;

  @CreateDateColumn({ name: 'created_at' })
  createdAt!: Date;

  @UpdateDateColumn({ name: 'updated_at' })
  updatedAt!: Date;
}
