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

export type AIProvider = 'openai' | 'anthropic' | 'google' | 'azure' | 'local';
export type ModelType = 'chat' | 'completion' | 'embedding' | 'image' | 'audio';

@Entity({ name: 'models', schema: 'ai' })
export class AIModel {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

  @Column({ name: 'name', type: 'varchar', length: 200 })
  name: string;

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

  @Index()
  @Column({ name: 'provider', type: 'varchar', length: 50 })
  provider: AIProvider;

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

  @Index()
  @Column({ name: 'model_type', type: 'varchar', length: 30 })
  modelType: ModelType;

  @Column({ name: 'max_tokens', type: 'int', nullable: true })
  maxTokens: number;

  @Column({ name: 'supports_functions', type: 'boolean', default: false })
  supportsFunctions: boolean;

  @Column({ name: 'supports_vision', type: 'boolean', default: false })
  supportsVision: boolean;

  @Column({ name: 'supports_streaming', type: 'boolean', default: true })
  supportsStreaming: boolean;

  @Column({ name: 'input_cost_per_1k', type: 'decimal', precision: 10, scale: 6, nullable: true })
  inputCostPer1k: number;

  @Column({ name: 'output_cost_per_1k', type: 'decimal', precision: 10, scale: 6, nullable: true })
  outputCostPer1k: number;

  @Column({ name: 'rate_limit_rpm', type: 'int', nullable: true })
  rateLimitRpm: number;

  @Column({ name: 'rate_limit_tpm', type: 'int', nullable: true })
  rateLimitTpm: number;

  @Index()
  @Column({ name: 'is_active', type: 'boolean', default: true })
  isActive: boolean;

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

  @Column({ name: 'metadata', type: 'jsonb', default: {} })
  metadata: Record<string, any>;

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

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