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

/** तकेता पत्र — Collection/Recovery Notice */
@Entity({ name: 'taketa_patras' })
export class TaketaPatra {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

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

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

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

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

  /** applicant | guarantor */
  @Column({ type: 'varchar', length: 30, default: 'applicant' })
  type!: string;

  /** 1st_notice | 2nd_notice | 3rd_notice | final_notice */
  @Column({ type: 'varchar', length: 40, nullable: true })
  letterType?: string;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  /** draft | sent | acknowledged */
  @Column({ type: 'varchar', length: 30, default: 'draft' })
  status!: string;

  @Column({ type: 'text', 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;
}
