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

@Entity('disabled_person_guardian_phone')
export class DisabledPersonGuardianPhone {
  @PrimaryGeneratedColumn({
    name: 'id',
    type: 'int',
    comment: '监护人电话ID'
  })
  id!: number;

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

  @Column({
    name: 'phone_number',
    type: 'varchar',
    length: 20,
    nullable: false,
    comment: '监护人电话号码'
  })
  phoneNumber!: string;

  @Column({
    name: 'relationship',
    type: 'varchar',
    length: 50,
    nullable: false,
    comment: '与残疾人的关系（如：父母、配偶、子女等）'
  })
  relationship!: string;

  @Column({
    name: 'is_primary',
    type: 'smallint',
    nullable: false,
    default: 0,
    comment: '是否为主要联系人：1-是，0-否'
  })
  isPrimary!: number;

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