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

@Entity('disabled_bank_card')
export class DisabledBankCard {
  @PrimaryGeneratedColumn({
    name: 'card_id',
    type: 'int',
    comment: '银行卡ID'
  })
  id!: number;

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

  @Column({
    name: 'sub_bank_name',
    type: 'varchar',
    length: 100,
    nullable: false,
    comment: '发卡支行'
  })
  subBankName!: string;

  @Column({
    name: 'bank_name_id',
    type: 'int',
    nullable: false,
    comment: '银行名称ID，引用bank_name表'
  })
  bankNameId!: number;

  @Column({
    name: 'card_number',
    type: 'varchar',
    length: 50,
    nullable: false,
    comment: '卡号'
  })
  cardNumber!: string;

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

  @Column({
    name: 'card_type',
    type: 'varchar',
    length: 20,
    nullable: true,
    comment: '银行卡类型：一类卡/二类卡'
  })
  cardType!: string | null;

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

  @Column({
    name: 'is_default',
    type: 'smallint',
    nullable: false,
    default: 0,
    comment: '是否默认：1-是，0-否'
  })
  isDefault!: number;

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

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

  // 关系定义 - 银行名称
  @ManyToOne(() => BankName, { onDelete: 'RESTRICT' })
  @JoinColumn({ name: 'bank_name_id' })
  bankName!: BankName;
}