import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, OneToMany, Index } from 'typeorm';
import { DisabledBankCard } from './disabled-bank-card.entity';
import { DisabledPhoto } from './disabled-photo.entity';
import { DisabledRemark } from './disabled-remark.entity';
import { DisabledVisit } from './disabled-visit.entity';

@Entity('disabled_person')
@Index(['name'])
@Index(['jobStatus'])
@Index(['disabilityType'])
export class DisabledPerson {
  @PrimaryGeneratedColumn({
    name: 'person_id',
    type: 'int',
    comment: '残疾人ID'
  })
  id!: number;

  @Column({
    name: 'name',
    type: 'varchar',
    length: 50,
    nullable: false,
    comment: '姓名'
  })
  name!: string;

  @Column({
    name: 'gender',
    type: 'char',
    length: 1,
    nullable: false,
    comment: '性别：男/女'
  })
  gender!: string;

  @Column({
    name: 'id_card',
    type: 'varchar',
    length: 20,
    nullable: false,
    comment: '身份证号'
  })
  @Index('idx_id_card', { unique: true })
  idCard!: string;

  @Column({
    name: 'disability_id',
    type: 'varchar',
    length: 50,
    nullable: false,
    comment: '残疾证号'
  })
  @Index('idx_disability_id', { unique: true })
  disabilityId!: string;

  @Column({
    name: 'disability_type',
    type: 'varchar',
    length: 50,
    nullable: false,
    comment: '残疾类型'
  })
  disabilityType!: string;

  @Column({
    name: 'disability_level',
    type: 'varchar',
    length: 20,
    nullable: false,
    comment: '残疾等级'
  })
  disabilityLevel!: string;

  @Column({
    name: 'id_address',
    type: 'varchar',
    length: 200,
    nullable: false,
    comment: '身份证地址'
  })
  idAddress!: string;

  @Column({
    name: 'id_valid_date',
    type: 'date',
    nullable: true,
    comment: '身份证有效期'
  })
  idValidDate!: Date | null;

  @Column({
    name: 'disability_valid_date',
    type: 'date',
    nullable: true,
    comment: '残疾证有效期'
  })
  disabilityValidDate!: Date | null;

  @Column({
    name: 'birth_date',
    type: 'date',
    nullable: true,
    comment: '出生日期'
  })
  birthDate!: Date | null;

  @Column({
    name: 'phone',
    type: 'varchar',
    length: 20,
    nullable: false,
    comment: '联系方式'
  })
  phone!: string;

  @Column({
    name: 'can_direct_contact',
    type: 'smallint',
    nullable: false,
    default: 1,
    comment: '是否可直接联系：1-是，0-否'
  })
  canDirectContact!: number;

  @Column({
    name: 'is_married',
    type: 'smallint',
    nullable: true,
    comment: '是否已婚：1-是，0-否'
  })
  isMarried!: number | null;

  @Column({
    name: 'nation',
    type: 'varchar',
    length: 20,
    nullable: true,
    comment: '民族'
  })
  nation!: string | null;

  @Column({
    name: 'province',
    type: 'varchar',
    length: 50,
    nullable: false,
    comment: '省级'
  })
  province!: string;

  @Column({
    name: 'city',
    type: 'varchar',
    length: 50,
    nullable: false,
    comment: '市级'
  })
  city!: string;

  @Column({
    name: 'district',
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '区县级'
  })
  district!: string | null;

  @Column({
    name: 'detailed_address',
    type: 'varchar',
    length: 200,
    nullable: true,
    comment: '详细地址'
  })
  detailedAddress!: string | null;

  @Column({
    name: 'is_in_black_list',
    type: 'smallint',
    nullable: false,
    default: 0,
    comment: '是否在黑名单中：1-是，0-否'
  })
  isInBlackList!: number;

  @Column({
    name: 'job_status',
    type: 'smallint',
    nullable: false,
    default: 0,
    comment: '在职状态：0-未在职，1-已在职'
  })
  jobStatus!: number;

  @Column({
    name: 'specific_disability',
    type: 'varchar',
    length: 500,
    nullable: true,
    comment: '具体残疾部位和情况'
  })
  specificDisability!: string | null;

  @CreateDateColumn({
    name: 'create_time',
    type: 'timestamp',
    nullable: false,
    comment: '创建时间'
  })
  createTime!: Date;

  @UpdateDateColumn({
    name: 'update_time',
    type: 'timestamp',
    nullable: false,
    comment: '更新时间'
  })
  updateTime!: Date;

  // 关系定义
  @OneToMany(() => DisabledBankCard, (bankCard: DisabledBankCard) => bankCard.person)
  bankCards!: DisabledBankCard[];

  @OneToMany(() => DisabledPhoto, (photo: DisabledPhoto) => photo.person)
  photos!: DisabledPhoto[];

  @OneToMany(() => DisabledRemark, (remark: DisabledRemark) => remark.person)
  remarks!: DisabledRemark[];

  @OneToMany(() => DisabledVisit, (visit: DisabledVisit) => visit.person)
  visits!: DisabledVisit[];
}