// server/src/model-config/model-config.entity.ts
import {
  Column,
  CreateDateColumn,
  Entity,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity('model_configs')
export class ModelConfig {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'text' })
  name: string;

  @Column({ type: 'text' })
  modelId: string;

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

  @Column({ type: 'text', nullable: true })
  apiKey?: string; // Should be encrypted in production

  @Column({ type: 'text' })
  type: string; // ModelType enum values

  @Column({ type: 'integer', nullable: true })
  dimensions?: number; // Embedding model dimensions, auto-detected and saved by system

  // ==================== Additional Fields ====================
  // The following fields are only meaningful for embedding/rerank models

  /**
   * Model input token limit
   * Example: OpenAI=8191, Gemini=2048
   */
  @Column({ type: 'integer', nullable: true, default: 8191 })
  maxInputTokens?: number;

  /**
   * Batch processing limit (max inputs per request)
   * Example: OpenAI=2048, Gemini=100
   */
  @Column({ type: 'integer', nullable: true, default: 2048 })
  maxBatchSize?: number;

  /**
   * Whether this is a vector model (for system identification)
   */
  @Column({ type: 'boolean', default: false })
  isVectorModel?: boolean;

  /**
   * Whether to enable this model
   * Users can disable models they don't use to prevent accidental selection
   */
  @Column({ type: 'boolean', default: true })
  isEnabled?: boolean;

  /**
   * Whether to use this model as default
   * Only one default allowed per type (llm, embedding, rerank)
   */
  @Column({ type: 'boolean', default: false })
  isDefault?: boolean;

  /**
   * Model provider name (for display and identification)
   * Example: "OpenAI", "Google Gemini", "Custom"
   */
  @Column({ type: 'text', nullable: true })
  providerName?: string;

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

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