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

/**
 * User Preferences Entity (schema: core_settings.user_preferences)
 *
 * Personal preferences for individual users.
 * These are user-specific settings like theme, language, notification preferences.
 *
 * Common keys:
 * - ui.theme: 'light' | 'dark' | 'system'
 * - ui.language: ISO language code
 * - ui.dateFormat: Date format string
 * - ui.numberFormat: Number format locale
 * - notifications.email: boolean
 * - notifications.push: boolean
 * - notifications.inApp: boolean
 */
@Entity({ name: 'user_preferences', schema: 'core_settings' })
@Unique(['userId', 'key'])
export class UserPreference {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index()
  @Column({ name: 'user_id', type: 'uuid' })
  userId: string;

  @Index()
  @Column({ name: 'key', type: 'varchar', length: 100 })
  key: string;

  @Column({ name: 'value', type: 'jsonb' })
  value: any;

  @Column({ name: 'synced_at', type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
  syncedAt: Date;

  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
  updatedAt: Date;
}
