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

@Entity('files')
@Index('idx_files_tenant', ['tenantId'])
@Index('idx_files_tenant_user', ['tenantId', 'userId'])
@Index(['userId', 'createdAt'])
@Index(['conversationId', 'createdAt'])
export class FileORM {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'tenant_id', type: 'uuid' })
  tenantId: string;

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

  @Column({ name: 'conversation_id', type: 'uuid', nullable: true })
  @Index()
  conversationId: string | null;

  @Column({ name: 'original_name', type: 'varchar', length: 500 })
  originalName: string;

  @Column({ name: 'storage_path', type: 'varchar', length: 1000 })
  storagePath: string;

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

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

  @Column({ type: 'bigint' })
  size: number;

  @Column({ type: 'varchar', length: 50, default: 'uploading' })
  status: string;

  @Column({ name: 'thumbnail_path', type: 'varchar', nullable: true })
  thumbnailPath: string | null;

  @Column({ type: 'jsonb', nullable: true })
  metadata: Record<string, unknown> | null;

  @Column({ name: 'extracted_text', type: 'text', nullable: true })
  extractedText: string | null;

  @Column({ name: 'error_message', type: 'varchar', nullable: true })
  errorMessage: string | null;

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

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

  @Column({ name: 'deleted_at', type: 'timestamp', nullable: true })
  deletedAt: Date | null;
}
