// server/src/user-setting/user-setting.entity.ts
import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  OneToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { User } from '../user/user.entity'; 

@Entity('user_settings')
export class UserSetting {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'text', unique: true, nullable: true }) // Ensure one-to-one relationship via unique userId, but allow null for global
  userId: string;

  @OneToOne(() => User, (user) => user.userSetting, { onDelete: 'CASCADE', nullable: true })
  @JoinColumn({ name: 'userId' })
  user: User;

  @Column({ type: 'boolean', default: false })
  isGlobal: boolean;

  @Column({ type: 'text', default: 'gpt-3.5-turbo' })
  selectedLLMId: string;

  @Column({ type: 'text', default: 'text-embedding-3-small' })
  selectedEmbeddingId: string;

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

  @Column({ type: 'real', default: 0.7 })
  temperature: number;

  @Column({ type: 'integer', default: 2048 })
  maxTokens: number;

  @Column({ type: 'boolean', default: false })
  enableRerank: boolean;

  @Column({ type: 'integer', default: 5 })
  topK: number;

  @Column({ type: 'real', default: 0.3 })
  similarityThreshold: number;

  @Column({ type: 'real', default: 0.5 })
  rerankSimilarityThreshold: number;

  @Column({ type: 'boolean', default: false })
  enableFullTextSearch: boolean;

  @Column({ type: 'real', default: 0.7 })
  hybridVectorWeight: number;

  @Column({ type: 'boolean', default: false })
  enableQueryExpansion: boolean;

  @Column({ type: 'boolean', default: false })
  enableHyDE: boolean;

  @Column({ type: 'integer', default: 1000 })
  chunkSize: number;

  @Column({ type: 'integer', default: 100 })
  chunkOverlap: number;

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

  @Column({ type: 'text', default: 'zh' })
  language: string;

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

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

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