import {
  Column,
  CreateDateColumn,
  DeleteDateColumn,
  Entity,
  Index,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity({ name: 'deposit_accounts' })
export class DepositAccount {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Index()
  @Column({ type: 'varchar', length: 30 })
  accountNumber!: string;

  @Index()
  @Column({ type: 'varchar', length: 36 })
  memberId!: string;

  @Column({ type: 'varchar', length: 250 })
  memberName!: string;

  @Column({ type: 'varchar', length: 250, nullable: true })
  memberCode?: string;

  /** saving_type lookup code: fixed_deposit | recurring | compulsory | etc. */
  @Column({ type: 'varchar', length: 60, nullable: true })
  savingType?: string;

  @Column({ type: 'varchar', length: 250, nullable: true })
  savingTypeName?: string;

  /** Duration value e.g. 12 */
  @Column({ type: 'varchar', nullable: true })
  duration?: string;

  /** Duration unit: months | years */
  @Column({ type: 'varchar', length: 20, nullable: true })
  durationType?: string;

  @Column({ type: 'decimal', precision: 14, scale: 2, default: 0 })
  principalAmount!: number;

  @Column({ type: 'decimal', precision: 6, scale: 2, nullable: true })
  interestPercent?: number;

  @Column({ type: 'decimal', precision: 14, scale: 2, default: 0 })
  totalInterestEarned!: number;

  @Column({ type: 'decimal', precision: 14, scale: 2, default: 0 })
  totalWithdrawn!: number;

  /** pending | active | matured | closed */
  @Column({ type: 'varchar', length: 20, default: 'pending' })
  status!: string;

  @Column({ type: 'varchar', nullable: true })
  openDate?: string;

  @Column({ type: 'varchar', nullable: true })
  openDateBs?: string;

  @Column({ type: 'varchar', nullable: true })
  maturityDate?: string;

  @Column({ type: 'varchar', nullable: true })
  maturityDateBs?: string;

  /** interest_receive_type: monthly | quarterly | maturity */
  @Column({ type: 'varchar', length: 30, nullable: true })
  interestReceiveType?: string;

  @Column({ type: 'boolean', default: false })
  isJointAccount!: boolean;

  @Column({ type: 'varchar', length: 250, nullable: true })
  jointMemberName?: string;

  @Column({ type: 'varchar', length: 36, nullable: true })
  officeId?: string;

  @Column({ type: 'varchar', length: 250, nullable: true })
  remarks?: string;

  @Column({ type: 'varchar', length: 36, nullable: true })
  createdById?: string;

  @Column({ type: 'varchar', length: 250, nullable: true })
  createdByName?: string;

  @CreateDateColumn()
  createdAt!: Date;

  @UpdateDateColumn()
  updatedAt!: Date;

  @DeleteDateColumn()
  deletedAt?: Date;
}
