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

@Entity('disabled_visit')
export class DisabledVisit {
  @PrimaryGeneratedColumn({
    name: 'visit_id',
    type: 'int',
    comment: '回访ID'
  })
  id!: number;

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

  @Column({
    name: 'visit_date',
    type: 'date',
    nullable: false,
    comment: '回访日期'
  })
  visitDate!: Date;

  @Column({
    name: 'visit_type',
    type: 'varchar',
    length: 50,
    nullable: false,
    comment: '回访类型'
  })
  visitType!: string;

  @Column({
    name: 'visit_content',
    type: 'text',
    nullable: false,
    comment: '回访内容'
  })
  visitContent!: string;

  @Column({
    name: 'visit_result',
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '回访结果'
  })
  visitResult?: string | null;

  @Column({
    name: 'next_visit_date',
    type: 'date',
    nullable: true,
    comment: '下次回访日期'
  })
  nextVisitDate?: Date | null;

  @Column({
    name: 'visitor_id',
    type: 'int',
    nullable: false,
    comment: '回访人ID'
  })
  visitorId!: number;

  @CreateDateColumn({
    name: 'visit_time',
    type: 'timestamp',
    nullable: false,
    default: () => 'CURRENT_TIMESTAMP',
    comment: '记录时间'
  })
  visitTime!: Date;

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