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

@Entity('usage_records')
@Index('idx_user', ['user_id'])
@Index('idx_feature', ['feature_key'])
@Index('idx_reference', ['reference_id'])
export class UsageRecord {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @Column({ type: 'int' })
  user_id: number;

  @Column({ length: 50 })
  feature_key: string;

  @Column({ type: 'int' })
  units_used: number;

  @Column({ type: 'int', nullable: true })
  reference_id: number;

  @CreateDateColumn()
  created_at: Date;
}
