import { Column, Entity, Index, PrimaryColumn } from 'typeorm';

/**
 * ORM Entity: TeamRating
 * 
 * Stores the current rating snapshot per team.
 * Uses JSONB for dimension data to keep schema flexible.
 */
@Entity({ name: 'team_ratings' })
@Index(['teamId'], { unique: true })
export class TeamRatingOrmEntity {
  @PrimaryColumn({ type: 'text' })
  teamId!: string;

  @Column({ type: 'jsonb' })
  driving!: {
    value: number;
    confidence: number;
    sampleSize: number;
    trend: 'rising' | 'stable' | 'falling';
    lastUpdated: Date;
  };

  @Column({ type: 'jsonb' })
  adminTrust!: {
    value: number;
    confidence: number;
    sampleSize: number;
    trend: 'rising' | 'stable' | 'falling';
    lastUpdated: Date;
  };

  @Column({ type: 'double precision' })
  overall!: number;

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

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

  @Column({ type: 'timestamptz' })
  updatedAt!: Date;
}