import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { LoanEntity } from './loan.entity';

@Entity('loan_payments')
export class LoanPaymentEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column() loan_id: number;
    @Column() no: number;
    @Column({ type: 'datetime' }) due: Date;

    @Column() principal_amount: number;
    @Column({ type: 'datetime', nullable: true }) principal_paid: Date | null;
    @Column({ type: 'int', nullable: true }) principal_amount_paid: number | null;

    @Column() interest_amount: number;
    @Column({ type: 'datetime', nullable: true }) interest_paid: Date | null;
    @Column({ type: 'int', nullable: true }) interest_amount_paid: number | null;

    @ManyToOne(() => LoanEntity, (loan) => loan.payments)
    @JoinColumn({ name: 'loan_id' })
    loan: LoanEntity;

    // @Column({ type: 'datetime', nullable: true }) last_payment: Date | null;
}
