import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { SolutionDesign } from './solution-design.entity';
import { File } from '@/server/modules/files/file.entity';

@Entity('solution_chapters')
export class SolutionChapter {
  @PrimaryGeneratedColumn({ unsigned: true, comment: '章节ID，主键自增' })
  id!: number;

  @Column({ name: 'solution_design_id', type: 'int', unsigned: true, comment: '方案设计ID' })
  solutionDesignId!: number;

  @ManyToOne(() => SolutionDesign, design => design.chapters)
  @JoinColumn({ name: 'solution_design_id', referencedColumnName: 'id' })
  solutionDesign!: SolutionDesign;

  @Column({ name: 'chapter_number', type: 'int', comment: '章节编号' })
  chapterNumber!: number;

  @Column({ name: 'title', type: 'varchar', length: 255, comment: '章节标题' })
  title!: string;

  @Column({ name: 'content', type: 'text', nullable: true, comment: '章节内容' })
  content!: string | null;

  @Column({ name: 'original_content', type: 'text', nullable: true, comment: '原始内容' })
  originalContent!: string | null;

  @Column({ name: 'modification_instructions', type: 'text', nullable: true, comment: '修改说明' })
  modificationInstructions!: string | null;

  @Column({ name: 'file_id', type: 'int', unsigned: true, nullable: true, comment: '章节文件ID' })
  fileId!: number | null;

  @ManyToOne(() => File)
  @JoinColumn({ name: 'file_id', referencedColumnName: 'id' })
  file!: File | null;

  @Column({ name: 'status', type: 'varchar', length: 20, default: 'pending', comment: '状态：pending-待处理, reviewing-审核中, completed-已完成' })
  status!: string;

  @Column({ name: 'ai_suggestions', type: 'text', nullable: true, comment: 'AI修改建议' })
  aiSuggestions!: string | null;

  @Column({ name: 'version', type: 'int', default: 1, comment: '版本号' })
  version!: number;

  @Column({ name: 'is_deleted', type: 'tinyint', default: 0, comment: '是否删除：0-未删除，1-已删除' })
  isDeleted!: number;

  @CreateDateColumn({ name: 'created_at', comment: '创建时间' })
  createdAt!: Date;

  @UpdateDateColumn({ name: 'updated_at', comment: '更新时间' })
  updatedAt!: Date;
}