import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Tenant } from '../../tenant/tenant.entity';
import { KnowledgeBase } from '../../knowledge-base/knowledge-base.entity';
import { KnowledgeGroup } from '../../knowledge-group/knowledge-group.entity';

@Entity('assessment_templates')
export class AssessmentTemplate {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'tenant_id', nullable: true })
  tenantId: string;

  @ManyToOne(() => Tenant, { nullable: true, onDelete: 'CASCADE' })
  @JoinColumn({ name: 'tenant_id' })
  tenant: Tenant;

  @Column()
  name: string;

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

  @Column({ type: 'simple-json', nullable: true })
  keywords: string[];

  @Column({ type: 'int', name: 'question_count', default: 5 })
  questionCount: number;

  @Column({
    type: 'simple-json',
    name: 'difficulty_distribution',
    nullable: true,
  })
  difficultyDistribution: {
    standard: number;
    advanced: number;
    specialist: number;
  };

  @Column({ type: 'varchar', default: 'technical' })
  style: string;

  @Column({ name: 'knowledge_base_id', nullable: true })
  knowledgeBaseId: string | null;

  @ManyToOne(() => KnowledgeBase, { nullable: true })
  @JoinColumn({ name: 'knowledge_base_id' })
  knowledgeBase: KnowledgeBase;

  @Column({ name: 'knowledge_group_id', nullable: true })
  knowledgeGroupId: string | null;

  @ManyToOne(() => KnowledgeGroup, { nullable: true })
  @JoinColumn({ name: 'knowledge_group_id' })
  knowledgeGroup: KnowledgeGroup;

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

  @Column({ type: 'int', default: 1 })
  version: number;

  @Column({ name: 'created_by', nullable: true })
  createdBy: string;

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

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