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

@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; 

  
  

  
  @Column({ type: 'integer', nullable: true, default: 8191 })
  maxInputTokens?: number;

  
  @Column({ type: 'integer', nullable: true, default: 2048 })
  maxBatchSize?: number;

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

  
  @Column({ type: 'boolean', default: true })
  isEnabled?: boolean;

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

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

  

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

  // null = global/system model (visible to all tenants)
  // set = private to this tenant
  @Column({ type: 'text', nullable: true, name: 'tenant_id' })
  tenantId: string;

  @ManyToOne(() => User, (user) => user.modelConfigs, {
    onDelete: 'CASCADE',
    nullable: true,
  })
  @JoinColumn({ name: 'userId' })
  user: User | null;

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

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