import {
    Column,
    CreateDateColumn,
    Entity,
    JoinColumn,
    OneToOne,
    PrimaryGeneratedColumn,
    UpdateDateColumn,
} from 'typeorm';
import { Tenant } from './tenant.entity';

/**
 * Organization-wide default settings.
 * UserSetting can still override these on a per-user basis.
 */
@Entity('tenant_settings')
export class TenantSetting {
    @PrimaryGeneratedColumn('uuid')
    id: string;

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

    @OneToOne(() => Tenant, { onDelete: 'CASCADE' })
    @JoinColumn({ name: 'tenantId' })
    tenant: Tenant;

    // Default LLM model (override per user in UserSetting)
    @Column({ type: 'text', nullable: true })
    selectedLLMId: string;

    // Default embedding model
    @Column({ type: 'text', nullable: true })
    selectedEmbeddingId: string;

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

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

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

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

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

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

    @Column({ type: 'boolean', default: false })
    enableRerank: 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: 'boolean', default: true })
    isNotebookEnabled: boolean;

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

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

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

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

    // The model IDs that the Tenant Admin has enabled for this tenant
    @Column({ type: 'simple-array', nullable: true })
    enabledModelIds: string[];

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

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