import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, CreateDateColumn } from 'typeorm';
import { DisabledPerson } from './disabled-person.entity';
import { File } from '@d8d/file-module';

@Entity('disabled_photo')
export class DisabledPhoto {
  @PrimaryGeneratedColumn({
    name: 'photo_id',
    type: 'int',
    comment: '照片ID'
  })
  id!: number;

  @Column({
    name: 'person_id',
    type: 'int',
    nullable: false,
    comment: '残疾人ID'
  })
  personId!: number;

  @Column({
    name: 'photo_type',
    type: 'varchar',
    length: 50,
    nullable: false,
    comment: '照片类型'
  })
  photoType!: string;

  @Column({
    name: 'file_id',
    type: 'int',
    nullable: false,
    comment: '文件ID，引用files表'
  })
  fileId!: number;

  @CreateDateColumn({
    name: 'upload_time',
    type: 'timestamp',
    nullable: false,
    default: () => 'CURRENT_TIMESTAMP',
    comment: '上传时间'
  })
  uploadTime!: Date;

  @Column({
    name: 'can_download',
    type: 'smallint',
    nullable: false,
    default: 1,
    comment: '是否可下载：1-是，0-否'
  })
  canDownload!: number;

  // 关系定义 - 残疾人
  @ManyToOne(() => DisabledPerson, person => person.photos, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'person_id' })
  person!: DisabledPerson;

  // 关系定义 - 文件
  @ManyToOne(() => File, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'file_id' })
  file!: File;
}