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

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

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

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

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

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

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

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

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

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

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