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

@Entity('templates')
export class Template {
  @PrimaryGeneratedColumn({ unsigned: true, comment: '模板ID，主键自增' })
  id!: number;

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

  @Column({ name: 'description', type: 'text', nullable: true, comment: '模板描述' })
  description!: string | null;

  @Column({ name: 'file_id', type: 'int', unsigned: true, comment: '关联文件ID' })
  fileId!: number;

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

  @Column({ name: 'category', type: 'varchar', length: 100, comment: '模板分类' })
  category!: string;

  @Column({ name: 'is_free', type: 'tinyint', default: 0, comment: '是否免费：0-收费，1-免费' })
  isFree!: number;

  @Column({ name: 'download_count', type: 'int', unsigned: true, default: 0, comment: '下载次数' })
  downloadCount!: number;

  @Column({ name: 'is_disabled', type: 'tinyint', default: 0, comment: '是否禁用：0-启用，1-禁用' })
  isDisabled!: number;

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

  @Column({ name: 'preview_url', type: 'varchar', length: 500, nullable: true, comment: '预览URL' })
  previewUrl!: string | null;

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

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